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;
}
};


查看22道真题和解析