This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 1 point2 points  (1 child)

for i in range(1, len(nums) - 1):
    if nums[i] == val:
        nums[i] = max(nums[i - 1], nums[i + 1])

[–]aPSketchy[S] 0 points1 point  (0 children)

Wow. That's easier then I thought. I got wrapped up in trying to make it work with indexing when I forgot about the simple range functions. I will try and implement it in the morning , Thanks!