From 76a200c3c6e3b2f04f0526c3d90b7290ba0c8ff2 Mon Sep 17 00:00:00 2001 From: leejw-lu Date: Sun, 18 Feb 2024 20:57:12 +0900 Subject: [PATCH] =?UTF-8?q?#9=20443=EB=B2=88=20String=20Compression?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leetcode/443_String Compression.py | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 leetcode/443_String Compression.py diff --git a/leetcode/443_String Compression.py b/leetcode/443_String Compression.py new file mode 100644 index 0000000..5328aa2 --- /dev/null +++ b/leetcode/443_String Compression.py @@ -0,0 +1,55 @@ +#After you are done modifying the input array ~ + +from collections import deque +class Solution: + def compress(self, chars: List[str]) -> int: + result=0 + i=0 + + while i1: + for c in str(count): #10이상인 경우 split 할 수 있게. + chars[result]=c + result+=1 + + return result + + # if len(chars)==1: + # return 1 + + # result=[] + # count=1 + + # for i in range(1,len(chars)): + # if chars[i-1]!=chars[i]: + # if count==1: #중복원소 없을 경우 숫자X + # result.append(chars[i-1]) + # else: + # result.append(chars[i-1]) + # #count 10이상이면 split + # if count>=10: + # result.append(str(count//10)) + # result.append(str(count%10)) + # else: + # result.append(str(count)) + # count=1 # 초기화 + # else: + # count+=1 + # if i==len(chars)-1: + # result.append(chars[i-1]) + # if count>=10: + # result.append(str(count//10)) + # result.append(str(count%10)) + # else: + # result.append(str(count)) + + # #print(result) + # idx=len(result) + # return idx \ No newline at end of file