-
Notifications
You must be signed in to change notification settings - Fork 2
/
217.py
43 lines (35 loc) · 1.05 KB
/
217.py
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
# [ LeetCode ] 217. Contains Duplicate
def solution(nums: list[int]) -> bool:
numbers: set = set()
for number in nums:
if number in numbers:
return True
else:
numbers.add(number)
return False
def another_solution(nums: list[int]) -> bool:
numbers: dict[int, bool] = {}
for number in nums:
if number in numbers:
return True
else:
numbers[number] = True
return False
if __name__ == "__main__":
cases: list[dict[str, dict[str, list[int]] | bool]] = [
{
"input": { "nums": [1, 2, 3, 1] },
"output": True
},
{
"input": { "nums": [1, 2, 3, 4] },
"output": False
},
{
"input": { "nums": [1, 1, 1, 3, 3, 4, 3, 2, 4, 2] },
"output": True
}
]
for case in cases:
assert case["output"] == solution(nums=case["input"]["nums"])
assert case["output"] == another_solution(nums=case["input"]["nums"])