728x90
<문제 링크>
https://leetcode.com/problems/permutation-in-string/
Permutation in String - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
<문제 풀이>
- 순서 상관없이 s2 내에 연속해서 s1의 값이 들어있으면 됨
- 그 값이 몇개 있는지만 확인하면 되므로 Counter 라이브러리 이용
<코드>
from collections import Counter
class Solution:
def checkInclusion(self, s1: str, s2: str) -> bool:
for i in range(len(s2)-len(s1)+1):
if Counter(s1) == Counter(s2[i:i+len(s1)]):
return True
<고쳐야 할 점>
- from collections import Counter 기억하기
'두두의 알고리즘 > 문제' 카테고리의 다른 글
[이분탐색] 릿코드 Medium 33 'Search in Rotated Sorted Array' (Python) (0) | 2022.02.03 |
---|---|
[이분탐색] 릿코드 Medium 34 'Find First and Last Position of Element in Sorted Array' (Python) (0) | 2022.02.03 |
[동적계획법] 릿코드 Medium 198 'House Robber' (Python) (0) | 2022.01.27 |
[동적계획법] 릿코드 Easy 70 'Climbing Stairs' (Python) (0) | 2022.01.25 |
[비트연산] 릿코드 Easy 190 'Reverse Bits' (Python) (0) | 2022.01.23 |