IT_Baekjoon 단계별로 풀어보기/문자열

1157_Python // 단어 공부 (실패)

Pangaea_T 2020. 1. 12. 23:28

Python

import sys

s = sys.stdin.readline().upper()
c = 'A'
for i in range(len(s)-1) :
    if(s.count(s[i]) > s.count(c) and c != "?") :
        c = s[i]
    elif(s.count(s[i]) == s.count(c) and s[i] != c) :
        c = "?"
print(c)


이 코드는 아래 코드가 if문이 너무 많아서 그런가 해서 줄여본 코드입니다 하지만 두 코드 모두 시간초과가 뜨네요

import sys

s = sys.stdin.readline().upper()
c = 'a'
for i in range(len(s)) :
if(s.count(s[i]) >= s.count(c)) :
if(s.count(s[i]) == s.count(c) and s[i] != c) :
c = '?'
elif(c != '?') :
c = s[i]
print(c)




===
pypy3가 더 빠르다고 해서 써봤지만 안됬네요
왜 느린지 어떻게 짜야하는지 알아봐야겠습니다