CS/algorithm & data structure

[파이썬 알고리즘 인터뷰] 문자열 조작

hjkim0502 2022. 2. 22. 17:53

125. valid palindrome

- str.isalnum()이나 정규식으로 전처리

- 데크로 최적화

- pop()이나 슬라이싱으로 판별

 

344. reverse string

- 투포인터로 스왑

- list.reverse()

- s[:]

 

937. reorder log files

- str.isdigit()

- 람다 표현식, 리스트 +

- list.sort(key=)

 

819. most common word

- 정규식으로 전처리

- collections.defaultdict(int), collections.Counter()

 

49. group anagrams

- ''.join()

- collections.defaultdict(list)

 

5. longest palindrome substring

- 투포인터 이동, 확장