-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 i<len(chars): | ||
cur=chars[i] | ||
count=0 | ||
while i<len(chars) and chars[i]==cur: | ||
count+=1 | ||
i+=1 | ||
chars[result]=cur | ||
result+=1 | ||
if count>1: | ||
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 |
76a200c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
문제 조건을 잘 읽어야 함!!!! 따로 배열 공간 쓰는게 아니라 입력으로 주어진 배열을 수정하라는 것이었음.