Share my clean java dp solution


  • 0
    W
    public boolean increasingTriplet(int[] nums) {
        int len = nums.length;
        if (nums == null || nums.length < 3) {
            return false;
        }
        int[] mark = new int[len];
        for (int i = 0; i < len; i++) {
            mark[i] = 1;
        }
        for (int i = 0; i < len; i++) {
            int max = 0;
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    max = Math.max(max, mark[j]);
                    mark[i] = max + 1;
                    if (max + 1 >= 3) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

  • 0

    You should notice that the space complexity exceeds requirement.


Log in to reply
 

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