8000 fix the bug · segmond/leetcode@9e4c01b · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e4c01b

Browse files
andyli029haoel
authored andcommitted
fix the bug
1 parent eb6b031 commit 9e4c01b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

algorithms/cpp/majorityElement/majorityElement.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int majorityElement(vector<int> &num) {
3232
cnt++;
3333
}else{
3434
majority == num[i] ? cnt++ : cnt --;
35-
if (cnt >= num.size()/2) return majority;
35+
if (cnt > num.size()/2) return majority;
3636
}
3737
}
3838
return majority;
@@ -59,7 +59,8 @@ vector<int> split(const string &s, char delim) {
5959

6060
int main(int argc, char** argv)
6161
{
62-
string array = "1,2,1,2,1,2,1,2,1,2,1";
62+
//string array = "1,2,1,2,1,2,1,2,1,2,1";
63+
string array = "2,2,1,1,1";
6364
if (argc > 1){
6465
array = argv[1];
6566
}

0 commit comments

Comments
 (0)
0