674最长连续递增序列

class Solution {
public:
    int findLengthOfLCIS(vector<int>& nums) {
        stack<int> st;
        int ans = 0;
        for (auto num : nums) {
            if (st.empty() || st.top() < num) st.push(num);
            else {
                if (st.size() > ans) ans = st.size();
                while(!st.empty()) st.pop();
                st.push(num);
            }
        }
        if (st.size() > ans) ans = st.size();
        return ans;
    }
};

全部评论

相关推荐

04-28 22:33
已编辑
门头沟学院 C++
点赞 评论 收藏
分享
评论
点赞
7
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务