일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 링피트
- 잡생각
- realclass
- 화상영어
- 10분
- 월간
- 매일
- English
- Writing
- 사이드
- Problem Solving
- 3줄정리
- 프로젝트
- 괜찮음
- 파비최
- 만화도
- leetcode
- 리얼 클래스
- FIT XR
- 개발자
- 영어원서읽기
- 쓰릴오브파이트
- 읽기
- 30분
- 뭐든
- 영어공부
- Daily Challenge
- 미드시청
- 스탭퍼
- 운동
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.11.10 Today's Challenge 본문
https://leetcode.com/problems/count-number-of-homogenous-substrings/
Count Number of Homogenous Substrings - LeetCode
Can you solve this real interview question? Count Number of Homogenous Substrings - Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7. A string is homogenous if all the characters
leetcode.com
지난번에 이어서 streak 이라는 개념을 통해 풀면 됨.
문제가 잘 이해가 안되네.. 아니면 너무 쓱 보고 지나가나 ㅎㅎ
class Solution:
def countHomogenous(self, s: str) -> int:
ans = 0
streak = 0
MOD = 10 ** 9 + 7
for i in range(len(s)):
if i == 0 or s[i] == s[i-1]:
streak += 1
else:
streak = 1
ans = (ans + streak) % MOD
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.11.12 Today's Challenge (0) | 2023.11.12 |
---|---|
2023.11.11 Today's Challenge (1) | 2023.11.11 |
2023.11.09 Today's Challenge (0) | 2023.11.09 |
2023.11.08 Today's Challenge (0) | 2023.11.08 |
2023.11.07 Today's Challenge (0) | 2023.11.07 |
Comments