Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LeetCode URL: https://leetcode.com/problems/longest-continuous-increasing-subsequence/
- /**
- * Sliding Window
- *
- * Time Complexity: O(N)
- *
- * Space Complexity: O(1)
- *
- * N = Length of input nums array.
- */
- class Solution {
- public int findLengthOfLCIS(int[] nums) {
- if (nums == null) {
- return 0;
- }
- if (nums.length <= 1) {
- return nums.length;
- }
- int maxLenHere = 1;
- int maxLenSoFar = 1;
- for (int i = 1; i < nums.length; i++) {
- if (nums[i] > nums[i - 1]) {
- maxLenHere++;
- } else {
- maxLenHere = 1;
- }
- maxLenSoFar = Math.max(maxLenSoFar, maxLenHere);
- }
- return maxLenSoFar;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement