Add solution for 0027 leetcode task

This commit is contained in:
pro100ton 2024-12-27 14:40:34 +03:00
parent 1c5b792565
commit 04948814fe
2 changed files with 24 additions and 0 deletions

View file

@ -1,3 +1,4 @@
# Link to task: https://leetcode.com/problems/remove-duplicates-from-sorted-array/
from typing import List
class Solution:

View file

@ -0,0 +1,23 @@
# Link: https://leetcode.com/problems/remove-element/description/
from typing import List
class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
c = 0
n = len(nums) - 1
while n >= 0:
if nums[n] == val:
del nums[n]
else:
c += 1
n -= 1
return c
if __name__ == "__main__":
# nums = [0, 1, 2, 2, 3, 0, 4, 2]
nums = [3, 2, 2, 3]
print(nums)
print(Solution().removeElement(nums, 3))
print(nums)