Short O(N) solution


  • 0
        int findLengthOfLCIS(vector<int>& a) {
            int maxL = 0, pre = INT_MIN, curL = 0;
            for (int x : a) {
                if (pre < x) maxL = max(maxL, ++curL);
                else curL = 1;
                pre = x;
            }
            return maxL;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.