Created
May 1, 2023 04:02
-
-
Save dbalatero/44ae2a784b50eec1f079673a9bb4bffa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def removeZeroes(nums: list[int]) -> list[int]: | |
count = len(nums) | |
left = 0 | |
while left < count and nums[left] == 0: | |
left += 1 | |
right = count - 1 | |
while right > left and nums[right] == 0: | |
right -= 1 | |
return nums[left:right + 1] | |
print(removeZeroes([0, 0, 0, 3, 1, 4, 1, 5, 9, 0, 0, 0, 0])) | |
# > [3, 1, 4, 1, 5, 9] | |
print(removeZeroes([0, 0, 0])) | |
# > [] | |
print(removeZeroes([8])) | |
# > [8] | |
print(removeZeroes([0, 1, 0, 1, 0])) | |
# > [1, 0, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment