Skip to content

Commit aa650f4

Browse files
committed
Nov 4
1 parent fd2fc3a commit aa650f4

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

2024-11-November-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| November 1 | [1957. Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string/) | Easy | Solved |
77
| November 2 | [2490. Circular Sentence](https://leetcode.com/problems/circular-sentence/) | Easy | Solved |
88
| November 3 | [796. Rotate String](https://leetcode.com/problems/rotate-string/) | Easy | Solved |
9-
| November 4 | []() | | |
9+
| November 4 | [3163. String Compression III](https://leetcode.com/problems/string-compression-iii/) | Medium | Solved |
1010
| November 5 | []() | | |
1111
| November 6 | []() | | |
1212
| November 7 | []() | | |
@@ -38,5 +38,5 @@
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 3 | 3 | 0 |
41-
| Medium | 0 | 0 | 0 |
41+
| Medium | 1 | 1 | 0 |
4242
| Hard | 0 | 0 | 0 |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution:
2+
def compressedString(self, word: str) -> str:
3+
curr_count = 0
4+
curr_char = None
5+
comp = ''
6+
for ch in word:
7+
if ch != curr_char:
8+
if curr_char is not None and curr_count > 0:
9+
comp += f'{curr_count}{curr_char}'
10+
curr_char = ch
11+
curr_count = 1
12+
else:
13+
curr_count += 1
14+
if curr_count == 9:
15+
comp += f'{curr_count}{curr_char}'
16+
curr_count = 0
17+
comp += (f'{curr_count}{curr_char}' if curr_count > 0 else '')
18+
return comp
19+
20+
21+
def main():
22+
word = 'abcde'
23+
assert Solution().compressedString(word) == '1a1b1c1d1e'
24+
25+
word = 'aaaaaaaaaaaaaabb'
26+
assert Solution().compressedString(word) == '9a5a2b'
27+
28+
29+
if __name__ == '__main__':
30+
main()

0 commit comments

Comments
 (0)