File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -13,19 +13,27 @@ public static class BoyerMooreMajorityVote
1313 /// <returns>Majority element or null.</returns>
1414 public static int ? FindMajority ( int [ ] nums )
1515 {
16- if ( nums ? . Length == 0 ) return null ;
16+ if ( nums ? . Length == 0 )
17+ {
18+ return null ;
19+ }
1720
1821 var candidate = FindCandidate ( nums ! ) ;
1922 return IsMajority ( nums ! , candidate ) ? candidate : null ;
2023 }
2124
2225 private static int FindCandidate ( int [ ] nums )
2326 {
24- int candidate = nums [ 0 ] , count = 1 ;
27+ int candidate = nums [ 0 ] ;
28+ int count = 1 ;
2529
2630 for ( int i = 1 ; i < nums . Length ; i ++ )
2731 {
28- if ( count == 0 ) candidate = nums [ i ] ;
32+ if ( count == 0 )
33+ {
34+ candidate = nums [ i ] ;
35+ }
36+
2937 count += nums [ i ] == candidate ? 1 : - 1 ;
3038 }
3139
You can’t perform that action at this time.
0 commit comments