
[LeetCode] 443. String Compression
·
코딩테스트/Python
🔗 Problem Linkhttps://leetcode.com/problems/string-compression/❔Thinking주어진 문자 배열을 압축한다 (ex - ['a','a'] -> ['a','2'])주어진 문자 배열에 압축한 결과를 저장한다.💻Solutiondef compress(self, chars: List[str]) -> int: compressed = [] n = len(chars) cnt = 0 for i in range(1, len(chars)): if chars[i] == chars[i-1]: cnt += 1 else: cnt += 1 compressed.append(cha..