Skip to content

Instantly share code, notes, and snippets.

@dongwooklee96
Created July 9, 2021 14:27
Show Gist options
  • Select an option

  • Save dongwooklee96/b20836a1bd83047e5608c01c16e2fca3 to your computer and use it in GitHub Desktop.

Select an option

Save dongwooklee96/b20836a1bd83047e5608c01c16e2fca3 to your computer and use it in GitHub Desktop.
2.3
"""
문제 2.3: 문자열이 주어지고, 해당 문자열이 회문인지 아닌지를 확인하라
## 제한 사항
1. 문자열의 입력 true, 혹인 false를 반환한다.
2. 비어있는 문자열은 회문이라고 간주한다.
"""
from typing import List
def isPalindrome(s: str) -> bool:
i = 0
j = len(s) - 1
s = s.lower()
while i < j:
while i < j:
if s[i].isalnum():
break
i += 1
while i < j:
if s[j].isalnum():
break
j -= 1
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
if __name__ == "__main__":
str = input()
print(isPalindrome(str))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment