Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

找出位置连续的最长递增序列 #76

Open
Liqiuyue9597 opened this issue Dec 10, 2020 · 1 comment
Open

找出位置连续的最长递增序列 #76

Liqiuyue9597 opened this issue Dec 10, 2020 · 1 comment

Comments

@Liqiuyue9597
Copy link
Owner

从一个整数数组中,找出位置连续的最长递增序列。
这道题类似于674. 最长连续递增序列,只不过这道题是找最长递增序列的个数,但是解法差不多。

function findList(nums){
    if(nums.length<=1) return nums;
    let temp = [], res = [];
    for(let i=1; i<nums.length; i++){
        if(nums[i]>nums[i-1]){
            temp.push(nums[i]);
        }else{
            if(res.length<temp.length){
                res = [];
                res.push(...temp);
            }
            temp=[];
        }
    }
    return res.length<temp.length ? temp : res;
}
@lijiayin0420
Copy link

请问循环从i=1开始的话,i=0如何被处理? 比如[1,3,5,4,7],这里的1就会被遗忘,结果等于[3,5]是错误的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants