Simple Java Solution


  • 0
    I

    Here is my simple Java solution.

    It is based on traversing array following incremental approach. Though takes one final comparison in order to ensure that if the latest continuous subsequence is at the end of the array then that is not skipped.

    public int findLengthOfLCIS(int[] nums) {
        int sequenceCounter 				= 1;
        int previousSequenceCounter	=	1;
        int numSize                 = nums.length;
        
        if(numSize<1 || numSize>10000){
          System.out.println("Array cannot be empty and nor it can exceed 10000");
          return 0;
        }
        for(int ctr =	0; ctr<numSize-1 ; ctr++){
          if(nums[ctr+1]>nums[ctr])  sequenceCounter++;
          else {
            if(sequenceCounter > previousSequenceCounter)
              previousSequenceCounter = sequenceCounter;
            sequenceCounter         = 1;
          }
        }
        if(sequenceCounter > previousSequenceCounter)  previousSequenceCounter = sequenceCounter;
        
        return previousSequenceCounter;
      }
    
    

    Regards,
    Salheen


Log in to reply
 

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