We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 009085f + 0d45bbc commit 174e8aaCopy full SHA for 174e8aa
algorithms/cpp/majorityElement/majorityElement.II.cpp
@@ -36,7 +36,7 @@ class Solution {
36
//the same algorithm as Majority Element I problem
37
int majority1=0, majority2=0, cnt1=0, cnt2=0;
38
for(auto item: nums) {
39
- if (cnt1 == 0) {
+ if (cnt1 == 0 && majority2 != item ) {
40
majority1 = item;
41
cnt1 = 1;
42
} else if (majority1 == item) {
0 commit comments