GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Leetcode-Algorithms/src/leetcode/HouseRobber.java at master · edyluisrey/Leetcode-Algorithms Expand file tree/ Copy pathHouseRobber.javaMore file actions 24 lines (19 loc) · 643 Bytes / Copy pathHouseRobber.javaFile metadata and controls24 lines (19 loc) · 643 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 package leetcode; public class HouseRobber { public static void main(String[] args) { HouseRobber test = new HouseRobber(); System.out.println(test.rob(new int[]{2,15,5,16})); } public int rob(int[] nums) { if(nums == null || nums.length ==0) return 0; int[] max = new int[nums.length]; if(nums.length==1) return nums[0]; if(nums.length==2) return Math.max(nums[0], nums[1]); max[0]= nums[0]; max[1]= Math.max(nums[0], nums[1]); for(int i = 2; i< nums.length; i++){ max[i]= Math.max(max[i-2]+nums[i], max[i-1]); } return max[nums.length-1]; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |