Skip to content

Instantly share code, notes, and snippets.

@trhgquan
Created October 19, 2019 10:05
Show Gist options
  • Save trhgquan/44aedf0fc213bf74b76d2b872cdd5c08 to your computer and use it in GitHub Desktop.
Save trhgquan/44aedf0fc213bf74b76d2b872cdd5c08 to your computer and use it in GitHub Desktop.
For more algorithm, visit https://github.com/trhgquan
def maximumNonAdj(arr):
arr.insert(0, 0)
brr = [0] * len(arr)
brr[1] = arr[1]
m = -100000000
for i in range(1, len(arr)):
brr[i] = max(arr[i] + brr[i - 2], brr[i - 1])
if (brr[i] > m): m = brr[i]
return m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment