LeetCode – H-Index II (Java)

Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?

Java Solution

public int hIndex(int[] citations) {
    if(citations==null || citations.length==0)
        return 0;
 
    int result = 0;
 
    for(int i=0; i<citations.length; i++){
        int smaller = Math.min(citations[i], citations.length-i);
        result = Math.max(result, smaller);
    }
 
    return result;
}
Category >> Algorithms  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>