My 0ms C++ solution


  • 1
    L
    int rob(vector<int>& nums) {
            int n = nums.size();
            if(n<1) return 0;
            int notin = 0;    //max value if not include the current item
            for(int i=1; i<n; i++){
                nums[i] += notin;
                notin = max(nums[i-1], notin);
            }
            return max(nums[n-1], notin);
    }

Log in to reply
 

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