Can someone confirm that the following sequence should return false? seq: [5,1,5,5,2,5,4]. if not please explain why.


  • 0
    S

    // had a very simple solution but a test case that I believe should've been false was returned as true

    // test case : [5,1,5,5,2,5,4]

    //my solution

    public class Solution {
    public boolean increasingTriplet(int[] nums) {
    int count = 0;
    for (int i = 1; i < nums.length; i++) {
    if (nums[i] > nums[i-1])
    count++;
    else
    count = 0;
    if (count == 2)
    return true;
    }
    return false;
    }
    }


  • 0
    S

    This seq should return true. nums[1]<nums[4]<nums[5].

    By the way your solution has some logica problem.it can only check nums[i]
    <nums[i+1]<nums[i+2].


  • 0
    S

    Thank you. I was under the impression that subsequences consisted of consecutive index values in the array. Back to the drawing board.


  • 0
    V

    I had the same mistake in the beginning. it's so easy to jump into that trap ;)


Log in to reply
 

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