My java solution works for not just triplet


  • 4
    S
    public boolean increasingTriplet(int[] nums) {
        int k = 3;
        int[] small = new int[k-1];
        for (int i = 0; i < small.length; i++) {
            small[i] = Integer.MAX_VALUE;
        }
        for (int num : nums) {
            int i = 0;
            while (i < small.length && small[i] < num) {
                i++;
            }
            if (i < small.length) {
                small[i] = num;
            } else {
                return true;
            }
        }
        return false;
    }

Log in to reply
 

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