-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchrome.py
More file actions
94 lines (85 loc) · 2.49 KB
/
chrome.py
File metadata and controls
94 lines (85 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#
# def threeSum(nums):
# a=[]
# for index,value in enumerate(nums):
# nums2=nums[:index]+nums[index+1:]
# for second_index in range(len(nums2)):
# nums3=nums2[:second_index]+nums2[second_index+1:]
# for third_index in range(len(nums3)):
# if nums[index]+nums2[second_index]+nums3[third_index]==0 and sorted([nums[index],nums2[second_index],nums3[third_index]]) not in a:
# a.append(sorted([nums[index],nums2[second_index],nums3[third_index]]))
# return a
# print(threeSum([-1,0,1,2,2,-1,-4]))
#
#
#
#
#
#
#
# def threeSum(nums):
# nums.sort() # Сортуємо
# res = []
# n = len(nums)
#
# for i in range(n):
# if i > 0 and nums[i] == nums[i-1]:
# continue # Пропускаємо дублікати
#
# left, right = i+1, n-1
# while left < right:
# total = nums[i] + nums[left] + nums[right]
# if total == 0:
# res.append([nums[i], nums[left], nums[right]])
# left += 1
# right -= 1
# while left < right and nums[left] == nums[left-1]:
# left += 1
# while left < right and nums[right] == nums[right+1]:
# right -= 1
# elif total < 0:
# left += 1
# else:
# right -= 1
# return res
# def palindrom(nums):
# left=0
# right=len(nums)-1
# while left<right:
# if not nums[left].isalnum():
# left+=1
# elif not nums[right].isalnum():
# right-=1
# elif nums[left]==nums[right]:
# left+=1
# right-=1
# else:
# return False
# return True
# print(palindrom('a,bb,ta'))
# def twosum(nums):
# nums.sort()
# left=0
# right=1
# while right<len(nums):
# if left==len(nums):
# left=0
# right+=1
# elif left==right:
# left+=1
# elif nums[left]+nums[right]==0:
# return [nums[left],nums[right]]
# left+=1
# return []
# print(twosum([-3, -1, 0, 1, 2]))
def remove_duplicates(nums):
nums.sort()
if not nums:
return 0
slow = 1 # позиція для запису
for fast in range(1, len(nums)):
if nums[fast] != nums[fast - 1]:
nums[slow] = nums[fast]
slow += 1
return nums[:slow]
print(remove_duplicates([1, 1, 3, 2, 3, 4,2]))