Easy and clear logic of JAVA solution with O(n), O(1)


  • 0
    F

    public class Solution {
    public int thirdMax(int[] nums) {
    Arrays.sort(nums);
    int l = nums.length;
    int count = 0;
    for(int i = l-1 ; i >= 1;i--){
    if(nums[i] != nums[i-1])
    count++;
    if(count == 2)
    return nums[i-1];
    }
    return nums[l-1];
    }
    }


Log in to reply
 

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