🔥Beats 99.71%🔥✅Easy (Java/C++/Python) Solution With Detailed Explanation✅
Intuition\nThe method findLengthOfLCIS employs a single pass through the array to identify and measure the lengths of continuous increasing subsequences, updati
# Intuition\nThe method `findLengthOfLCIS` employs a single pass through the array to identify and measure the lengths of continuous increasing subsequences, updating a count for each subsequence. It maintains and updates the maximum length (`ans`) of these subsequences encountered so far. Whenever a non-increasing pair is found, the count is reset, ensuring only continuous increasing subsequences are considered.\n\n![Screenshot (218).png](https://assets.leetcode.com/users/images/c4f3fb8a-d8a5-42d1-8e19-d04f22d4f3ee_1706244441.7049036.png)\n\n# Approach\n1. **Variable Initialization**: \n   - `n`: Stores the length of the input array `nums`.\n   - `ans`: Initially set to -1, this variable will hold the maximum length of an increasing subsequence found during the iteration. The initial value of -1 is a placeholder and will be updated during the iteration.\n   - `count`: Initialized to 1, this variable keeps track of the current length of an increasing subsequence.\n\n2. **Iterating Through the Array**: \n   - The loop iterates over the array elements, except for the last element, as the comparison is always made with the next element.\n   - `for (int i = 0; i < n - 1; i++)`: This loop iterates through the array elements.\n\n3. **Identifying Increasing Subsequences**: \n   - `if (nums[i] < nums[i + 1])`: If the current element is less than the next element, it indicates that the subsequence is still increasing, so `count` is incremented.\n   - `else`: If the current element is not less than the next element, it means the current increasing subsequence has ended. In this case, `ans` is updated to be the maximum of `ans` and `count`, and then `count` is reset to 1 to start counting the length of a new subsequence.\n\n4. **Final Check and Update**: \n   - After the loop, there\'s a final update to `ans`: `ans = Math.max(ans, count);`. This is necessary because the last increasing subsequence might be the longest, but it wouldn\'t be checked inside the loop as the loop ends before the last element.\n\n5. **Return the Result**: \n   - The method returns `ans`, which contains the length of the longest continuous increasing subsequence found in the array.\n\n# Complexity\n\n1. **Time Complexity: O(n)**\n   - The method iterates through the array `nums` exactly once. During this iteration, it performs constant-time operations for each element, such as comparison and updating the count and maximum length values.\n   - Since the number of operations is proportional to the length of the array, the time complexity is linear, or `O(n)`, where `n` is the number of elements in the array.\n\n2. **Space Complexity: O(1)**\n   - The space complexity is constant because the method uses a fixed number of variables (`n`, `ans`, `count`) regardless of the size of the input array.\n   - No additional data structures that grow with the input size are used, so the amount of space required remains the same, leading to a space complexity of `O(1)`.\n\n# Code\n```Java []\npublic class Solution {\n    public int findLengthOfLCIS(int[] nums) {\n        int n = nums.length;\n        int ans = -1;\n        int count = 1;\n        for (int i = 0; i < n - 1; i++) {\n            if (nums[i] < nums[i + 1]) {\n                count++;\n            } else {\n                ans = Math.max(ans, count);\n                count = 1;\n            }\n        }\n\n        ans = Math.max(ans, count);\n\n        return ans;\n    }\n}\n\n```\n```C++ []\nclass Solution {\npublic:\n    int findLengthOfLCIS(vector<int>& nums) {\n        int n = nums.size();\n        int ans = -1;\n        int count = 1;\n        for (int i = 0; i < n - 1; i++) {\n            if (nums[i] < nums[i + 1])\n                count++;\n            else {\n                ans = max(ans, count);\n                count = 1;\n            }\n        }\n\n        ans = max(ans, count);\n\n        return ans;\n    }\n};\n```\n```Python []\nfrom typing import List\n\nclass Solution:\n    def findLengthOfLCIS(self, nums: List[int]) -> int:\n        if not nums:\n            return 0\n\n        ans = 1\n        count = 1\n        for i in range(1, len(nums)):\n            if nums[i] > nums[i - 1]:\n                count += 1\n                ans = max(ans, count)\n            else:\n                count = 1\n\n        return ans\n\n```
['C++', 'Java', 'Python3']