mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 10:31:29 +08:00
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>
This commit is contained in:
@ -4,7 +4,7 @@ from typing import List
|
||||
|
||||
|
||||
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]))
|
||||
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user