Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b158702

Browse files
python: add problem 80 and unittest
1 parent 9396f41 commit b158702

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Python/sln_1_100/solution_81_90.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55

66
class Solution_81_90(object):
7+
def removeDuplicates(self, nums: List[int]) -> int:
8+
"""
9+
80
10+
:param nums:
11+
:return:
12+
"""
13+
14+
if len(nums) <= 2:
15+
return 2
16+
indicator = nums[0] ^ nums[1]
17+
idx = 1
18+
actual_len = len(nums)
19+
while idx < actual_len - 1:
20+
new_indicator = nums[idx] ^ nums[idx + 1]
21+
if indicator == 0 and new_indicator == 0:
22+
nums[idx:] = nums[idx + 1:]
23+
actual_len -= 1
24+
idx -= 1
25+
idx += 1
26+
indicator = new_indicator
27+
return actual_len
28+
729
def partition(self, head: ListNode, x: int) -> ListNode:
830
"""
931
86

Python/sln_1_100/test_solution_81_90.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ class Test_Solution_81_90(TestCase):
88
def setUp(self) -> None:
99
self.sln = Solution_81_90()
1010

11+
def test_removeDuplicates(self):
12+
arr = [1, 1, 1, 2, 2, 3]
13+
self.assertEqual(self.sln.removeDuplicates(arr), 5)
14+
arr1 = [1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5]
15+
self.assertEqual(self.sln.removeDuplicates(arr1), 9)
16+
1117
def test_partition(self):
1218
head = build_linked_list([1, 4, 3, 2, 5, 2])
1319
ret = self.sln.partition(head, 3)

0 commit comments

Comments
 (0)