We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d544ca4 + a28233d commit 4555282Copy full SHA for 4555282
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