Very Simple Java Code


  • 0
    J

    '''
    public class Solution {
    public int rob(int[] nums) {
    int a = 0;
    int b = 0;

        for(int i = 0; i < nums.length; i++){
            int c = b;
            b = b>a+nums[i]? b:a+nums[i];
            a = c;
        }
        return b;
    }
    

    }
    '''


Log in to reply
 

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