File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
2024-11-November-LeetCoding-Challenge Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 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 | [ ] ( ) | | |
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 |
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments