Very simple linear solution c++


  • 0
    P
    class Solution {
    public:
        int hIndex(vector<int>& citations) {
        	int hindex = 0, diff;
        	for(int i = 0; i < citations.size(); i++)
        	{
        		diff = citations.size() - i;
        		if(citations[i] >= diff)
        		{
        			if(hindex < diff)
        				hindex = diff;
        		}
    	    }
    
    	    return hindex;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.