Last active
January 30, 2019 01:42
-
-
Save atiq-cs/d4e5e37114d84e4afd72b129e932056f to your computer and use it in GitHub Desktop.
do max robbing with DP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// O(N), O(N) | |
public class Solution { | |
public int Rob(int[] nums) { | |
var dp = new int[nums.Length]; | |
for (int i=0; i<nums.Length; i++) | |
dp[i] = Math.Max((i < 2? 0 : dp[i-2]) + nums[i], i<1? 0 : dp[i-1]); | |
return nums.Length == 0 ? 0 : dp[nums.Length-1]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment