描述
給定一個未經排序的整數數組,找到最長且連續的的遞增序列,並返回該序列的長度。
示例
示例 1:
輸入: [1,3,5,4,7]輸出: 3解釋: 最長連續遞增序列是 [1,3,5], 長度為3。儘管 [1,3,5,7] 也是升序的子序列, 但它不是連續的,因為5和7在原數組裡被4隔開。
示例 2:
輸入: [2,2,2,2,2]輸出: 1解釋: 最長連續遞增序列是 [2], 長度為1。注意:數組長度不會超過10000。
Description
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).
Example
Example 1:Input: [1,3,5,4,7]Output: 3Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3. Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4. Example 2:Input: [2,2,2,2,2]Output: 1Explanation: The longest continuous increasing subsequence is [2], its length is 1.Note: Length of the array will not exceed 10,000.
`BitDance` `Amazon` `Microsoft` `Adobe` `Apple` `Google` `Tencent` `FaceBook` `Alibaba` `Yahoo` `Cisco` `HuaWei`解題
代碼
class Solution {public: int findLengthOfLCIS(vector<int>& nums) { if(nums.empty()) return 0; int res=1; int temp=1; for(int i=0;i+1<nums.size();++i){ if(nums[i+1]>nums[i]){ temp++; } else{ temp=1; } res=max(res,temp); } return res; }};