0ms easy JAVA solution


  • 2
    V

    public class Solution {

    public int rob(int[] nums) {
        int robPrev = 0;
        int leavePrev = 0;
        int temp;
        
        for(int i : nums) {
            temp = robPrev > leavePrev ? robPrev : leavePrev;
            robPrev = leavePrev + i;
            leavePrev = temp;
        }
        
        return robPrev > leavePrev ? robPrev : leavePrev;
    }
    

    }


Log in to reply
 

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