일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 미드시청
- 개발자
- 10분
- Daily Challenge
- 읽기
- 운동
- 월간
- Problem Solving
- FIT XR
- 괜찮음
- 30분
- 스탭퍼
- 만화도
- 매일
- 영어공부
- 뭐든
- leetcode
- 영어원서읽기
- Writing
- 프로젝트
- 사이드
- 3줄정리
- English
- 잡생각
- realclass
- 파비최
- 리얼 클래스
- 화상영어
- 쓰릴오브파이트
- 링피트
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.02.04 Today's Challenge 본문
https://leetcode.com/problems/permutation-in-string/
Permutation in String - LeetCode
Permutation in String - Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1's permutations is the substring of s2. Example 1: Input: s1 = "ab", s2 = "eidbaooo" Output:
leetcode.com
퍼뮤테이션 구하는 문제
class Solution:
def checkInclusion(self, s1: str, s2: str) -> bool:
n1 = len(s1)
n2 = len(s2)
if n1 > n2:
return False
arr1 = [0] * 26
arr2 = [0] * 26
for ch in s1:
arr1[ord(ch) - ord('a')] += 1
for i in range(n2):
arr2[ord(s2[i]) - ord('a')] += 1
if i>= n1:
arr2[ord(s2[i-n1]) - ord('a')] -= 1
if arr1 == arr2:
return True
return False
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.02.06 Today's Challenge (0) | 2023.02.06 |
---|---|
2023.02.05 Today's Challenge (0) | 2023.02.05 |
2023.02.03 Today's Challenge (0) | 2023.02.03 |
2023.02.02 Today's Challenge (0) | 2023.02.02 |
2023.02.01 Today's Challenge (0) | 2023.02.01 |
Comments