Euler problem 551 sol 1: Reduce McCabe code complexity (#2141) · TheAlgorithms/Python@fdc5bee · GitHub
Skip to content

Commit fdc5bee

Browse files
cclaussgithub-actions
andauthored
Euler problem 551 sol 1: Reduce McCabe code complexity (#2141)
* Euler problem 551 sol 1: Reduce McCabe code complexity As discussed in #2128 * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent d034add commit fdc5bee

3 files changed

Lines changed: 15 additions & 18 deletions

File tree

backtracking/knight_tour.py

Lines changed: 9 additions & 9 deletions

dynamic_programming/max_non_adjacent_sum.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def maximum_non_adjacent_sum(nums: List[int]) -> int:
7-
'''
7+
"""
88
Find the maximum non-adjacent sum of the integers in the nums input list
99
1010
>>> print(maximum_non_adjacent_sum([1, 2, 3]))
@@ -15,14 +15,15 @@ def maximum_non_adjacent_sum(nums: List[int]) -> int:
1515
0
1616
>>> maximum_non_adjacent_sum([499, 500, -3, -7, -2, -2, -6])
1717
500
18-
'''
18+
"""
1919
if not nums:
2020
return 0
2121
max_including = nums[0]
2222
max_excluding = 0
2323
for num in nums[1:]:
2424
max_including, max_excluding = (
25-
max_excluding + num, max(max_including, max_excluding)
25+
max_excluding + num,
26+
max(max_including, max_excluding),
2627
)
2728
return max(max_excluding, max_including)
2829

project_euler/problem_551/sol1.py

Lines changed: 2 additions & 6 deletions

0 commit comments

Comments
 (0)