Euler problem 551 sol 1: Reduce McCabe code complexity by cclauss · Pull Request #2141 · TheAlgorithms/Python · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions backtracking/knight_tour.py
7 changes: 4 additions & 3 deletions dynamic_programming/max_non_adjacent_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def maximum_non_adjacent_sum(nums: List[int]) -> int:
'''
"""
Find the maximum non-adjacent sum of the integers in the nums input list

>>> print(maximum_non_adjacent_sum([1, 2, 3]))
Expand All @@ -15,14 +15,15 @@ def maximum_non_adjacent_sum(nums: List[int]) -> int:
0
>>> maximum_non_adjacent_sum([499, 500, -3, -7, -2, -2, -6])
500
'''
"""
if not nums:
return 0
max_including = nums[0]
max_excluding = 0
for num in nums[1:]:
max_including, max_excluding = (
max_excluding + num, max(max_including, max_excluding)
max_excluding + num,
max(max_including, max_excluding),
)
return max(max_excluding, max_including)

Expand Down
8 changes: 2 additions & 6 deletions project_euler/problem_551/sol1.py