Skip to content

Commit ecd137a

Browse files
authored
Merge pull request #1296 from ivan1016017/june08
adding duplicates
2 parents 41e71c8 + 94d399a commit ecd137a

7 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import List
2+
3+
class Solution:
4+
5+
def algo_1(self, nums: List[int]):
6+
7+
8+
nums = [n for n in nums if n % 7 == 0]
9+
10+
11+
return len(nums), nums
12+
13+
14+
15+
solution = Solution()
16+
17+
print(solution.algo_1(nums=[1,2,7,14,34,35]))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import List
2+
3+
class Solution:
4+
5+
def algo_1(self, input_file):
6+
7+
8+
with open(input_file, 'r') as infile, \
9+
open('odd_numbers.txt', 'w') as odd_nums, \
10+
open('even_numbers.txt', 'w') as even_nums:
11+
12+
for line in infile:
13+
if not line:
14+
continue
15+
try:
16+
num = int(line)
17+
if num % 2 == 0:
18+
even_nums.write(f'{num}\n')
19+
else:
20+
odd_nums.write(f'{num}\n')
21+
except ValueError:
22+
continue
23+
24+
25+
26+
solution = Solution()
27+
28+
solution.algo_1(input_file='numbers.txt')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
4
2+
8
3+
10
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1
2+
3
3+
4
4+
8
5+
10
6+
7
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
3
3+
7
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
12+
if nums[i] != nums[i+1]:
13+
nums[j] = nums[i]
14+
j += 1
15+
16+
nums[j] = nums[len_nums - 1]
17+
18+
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_17\
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)