blob: def9b938321984c5d9ae72434b30c880817c47ff (
plain)
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
|
#!/usr/bin/env python
from collections import Counter
def twiceAppearance(str):
count = Counter()
for char in str:
count[char] += 1
if count[char] > 1:
return char
return "␀" # fallback
def solution(str):
print(f'Input: $str = "{str}"')
print(f'Output: "{twiceAppearance(str)}"')
print('Example 1:')
solution("acbddbca")
print('\nExample 2:')
solution("abccd")
print('\nExample 3:')
solution("abcdabbb")
print('\nExample 4:')
solution("abcdefg")
|