Coding Test & Algorithms/LeetCode-Python3(2)
-
[LeetCode] Python3 / 344. Reverse String
1. 문제 링크https://leetcode.com/problems/reverse-string/description/ 2. 문제 3. 소스코드class Solution: def reverseString(self, s: List[str]) -> None: s.reverse()- 파이썬 언어의 특징은 함수가 다양하다는 것이다. 이를 특성에 기반해 reverse() 함수를 이용해 문자열을 뒤집는다.
2024.10.07 -
[LeetCode] Python3 / 125. Valid Palindrome
1. 문제 링크https://leetcode.com/problems/valid-palindrome/ 2. 문제 3. 소스 코드 및 해설#전체 코드class Solution: def isPalindrome(self, s: str) -> bool: strs = [] for char in s: if char.isalnum(): strs.append(char.lower()) while len(strs) > 1: if strs.pop(0) != strs.pop(): #맨 앞 글자와 맨 뒷 글자 비교 return False return True1) cha..
2024.10.07