Skip to content

Commit ab25aec

Browse files
committed
adding algo
1 parent 954f671 commit ab25aec

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def removeDuplicates(self, nums: List[int]) -> int:
6+
7+
j = 0
8+
len_nums = len(nums)
9+
10+
for i in range(len_nums - 1):
11+
if nums[i] != nums[i+1]:
12+
nums[j] = nums[i]
13+
j += 1
14+
15+
nums[j] = nums[len_nums - 1]
16+
17+
return j + 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_21\
3+
.remove_duplicates import Solution
4+
5+
class RemoveDuplicatesTestCase(unittest.TestCase):
6+
7+
def test_remove_duplicates(self):
8+
solution = Solution()
9+
output = solution.removeDuplicates(nums=[1,1,2])
10+
target = 2
11+
self.assertEqual(output, target)

0 commit comments

Comments
 (0)