일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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분
- 쓰릴오브파이트
- 영어원서읽기
- 잡생각
- 링피트
- Problem Solving
- 사이드
- leetcode
- 파비최
- 30분
- 리얼 클래스
- 미드시청
- realclass
- 매일
- 괜찮음
- Daily Challenge
- FIT XR
- 운동
- 영어공부
- Writing
- 뭐든
- 월간
- 스탭퍼
- 개발자
- 읽기
- 프로젝트
- English
- 화상영어
- 3줄정리
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.02 Today's Challenge 본문
https://leetcode.com/problems/string-compression/
String Compression - LeetCode
Can you solve this real interview question? String Compression - Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: * If the group's leng
leetcode.com
문제 되게 이상하네 -_-
class Solution:
def compress(self, chars: List[str]) -> int:
ans = 0
i = 0
while i < len(chars):
letter = chars[i]
count = 0
while i < len(chars) and chars[i] == letter:
count += 1
i += 1
chars[ans] = letter
ans += 1
if count > 1:
for c in str(count):
chars[ans] = c
ans += 1
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.04 Today's Challenge (0) | 2023.03.04 |
---|---|
2023.03.03 Today's Challenge (0) | 2023.03.03 |
2023.03.01 Today's Challenge (0) | 2023.03.01 |
2023.02.28 Today's Challenge (0) | 2023.02.28 |
2023.02.27 Today's Challenge (0) | 2023.02.27 |
Comments