Skip to content

Commit b61d5b0

Browse files
committed
add solution containsDuplicate
1 parent 5acf128 commit b61d5b0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

contains-duplicate/JonghunLee.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# Time complexity: O(n)
3+
# The process of traversing a list to generate a set is proportional to the length of the input list.
4+
# Space complexity: O(n)
5+
# The size of the set for storing deduplicated elements is proportional to the length of the input list.
6+
7+
class Solution:
8+
def containsDuplicate(self, nums: list[int]) -> bool:
9+
list_len = len(nums)
10+
set_len = len(set(nums))
11+
12+
return list_len != set_len
13+
14+
if __name__ == "__main__":
15+
solution = Solution()
16+
17+
# test case
18+
test_string = [
19+
[1,2,3,1], # True
20+
[1,2,3,4], # False
21+
[1,1,1,3,3,4,3,2,4,2], # True
22+
]
23+
24+
for index, test in enumerate(test_string):
25+
print(f"start {index} test")
26+
print(f"input : {test}")
27+
print(f"Is valid palindrome ? {solution.containsDuplicate(test)}\n")

0 commit comments

Comments
 (0)