C++ 8ms DP with O(1) Space


  • 2
    S
        if (nums.empty()) return 0;
        int res = INT_MIN;
        int tmp = 0;
        for(int i=0; i<nums.size(); i++)
        {
            if (tmp<0) tmp =0;
            tmp +=nums[i];
            res = max(tmp, res);
        }
        return res;

Log in to reply
 

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