S1 = "level"
S2 = "korea"
n = len(S1)
def palindrome(S):
for x in range(n):
if S[x] != S[n-x-1]:
return False
return True
# 제한이 여유 있을 때
def simple_palindrome(S):
if S != S[::-1]:
return False
return True
print(palindrome(S1)) # True
print(simple_palindrome(S1)) # True
print(palindrome(S2)) # False
print(simple_palindrome(S2)) # False
알고리즘 이론/회문
댓글