T = str(input())
T = T.lower()
ans = []
count = 0
for i in T:
if T.count(i) >= count:
if [i, T.count(i)] in ans:
continue
ans.append([i, T.count(i)])
count_list = []
for i in ans:
count_list.append(i[1])
if count_list.count(max(count_list)) != 1:
print('?')
else:
max_num = 0
ans_alpha = ''
for i in ans:
if i[1] >= max_num:
max_num = i[1]
ans_alpha = i[0]
print(ans_alpha.upper())
처음에 이렇게 풀었는데 풀면서도 뭔가 반복문을 너무 사용하는거 같긴 했다.
입출력은 잘 되었지만 역시 시간초과...
빈 배열에 append하는 건 똑같지만 ?를 출력하는 과정을 간소화해서 통과했다.
T = input()
T = T.upper()
alpha = []
count = []
for i in T:
if i not in alpha:
alpha.append(i)
for i in alpha:
count.append(T.count(i))
if count.count(max(count)) > 1:
print('?')
else:
print(alpha[count.index(max(count))])