此篇文章為我的解題紀錄,程式碼或許並不是很完善

Leetcode - 26. Remove Duplicates from Sorted Array

解題思路

跑迴圈若是有重複的element則將該element從陣列裡刪除

我滴程式碼

1
2
3
4
5
6
7
8
9
10
11
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
while True:
size = len(nums)
for i in range(1, size):
if(nums[i] == nums[i-1]):
del nums[i]
break

if size == len(nums):
return size