Sharing my solution


  • 0
    S
    public class Solution {
        public int hIndex(int[] citations) {
            int n = citations.length; 
            if ( n == 0) return 0; 
            if (citations[n-1] == 0) return 0; 
            
            int res = 0;
            for (int i = citations.length - 1; i >= 0; i--) {
                if (citations[i] >= res) {
                    res++;
                    if (res > citations[i]) res--; 
                }
                else break; 
            }
            return res;
        }
    }

Log in to reply
 

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