leetcode 169. Majority Element

Orignal question can be found here.

My solution is as follows:

int majorityElement(int* nums, int numsSize)
{
        int cnt=0;
        int result=0;
        for(int i=0; i<numsSize; ++i)
        {
                if(cnt==0)
                {
                        result=nums[i];
                        ++cnt;
                        continue;
                }
                else
                {
                        if(result==nums[i])
                                ++cnt;
                        else
                                --cnt;
                }
        }
        return result;
}

One thought on “leetcode 169. Majority Element”

  1. I must say you have very interesting articles here.

    Your website should go viral. You need initial
    boost only. How to get it? Search for; Miftolo’s tools go viral

Leave a Reply

Your email address will not be published. Required fields are marked *