-
Notifications
You must be signed in to change notification settings - Fork 2
/
389.py
43 lines (37 loc) · 1.01 KB
/
389.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 ] 389. Find the Difference
def solution(s: str, t: str) -> str:
characters: dict[str, int] = {}
for character in s:
if character in characters:
characters[character] += 1
else:
characters[character] = 1
for character in t:
if character in characters:
if characters[character] == 0:
return character
else:
characters[character] -= 1
else:
return character
if __name__ == "__main__":
cases: list[dict[str, dict[str, str] | str]] = [
{
"input": {
"s": "abcd",
"t": "abcde",
},
"output": "e"
},
{
"input": {
"s": "",
"t": "y",
},
"output": "y"
}
]
for case in cases:
assert case["output"] == solution(
s=case["input"]["s"], t=case["input"]["t"]
)