Python String Parsing

Devedunkey
Nov 27, 2020

Check Valid Palindrome

words = [‘a’, ‘b’, ‘c’, ‘b’, ‘a’]

While len(words) > 1:

— — — — if words.pop(0) !=words.pop():

— — — — — — — — return False

Using Deque, the code can optimize the performance in speed. Deques is BigO(n)

def isPalindrome(self, s: str): -> bool:

— — — — strs: Deque = collections.deque()

— — — — for char in s:

— — — — —if char.isalum():

— — — — — — —strs.append(char.lower())

while len(strs) > 1:

— — — — if strs.popleft() !=strs.pop():

— — — — — — return False

return True

Slicing이 가장 속도가 빠르다.

--

--

Devedunkey
0 Followers

Education is key to success why developers are desperately learning every day.