Created
November 28, 2018 02:14
-
-
Save farsialgorithm/ba6959947a79b5fa72d53d1f8ae81467 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def non_conti(nums): | |
| if nums == []: | |
| return 0 | |
| if len(nums)==1: | |
| return nums[0] | |
| dp = [0] * (len(nums)+1) | |
| dp[1], dp[2] = nums[0], nums[1] | |
| for i in range(3, len(nums)+1): | |
| dp[i] = max(dp[i-2], dp[i-3]) + nums[i-1] | |
| return max(dp[-1], dp[-2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment