Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5169482

Browse files
committed
Create 1544-MakeTheStringGreat.py
1 parent 20375d4 commit 5169482

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

‎src/1544-MakeTheStringGreat.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
"""
3+
CREATED AT: 2022年11月08日
4+
5+
URL: https://leetcode.com/problems/make-the-string-great/
6+
7+
GITHUB: https://github.com/Jiezhi/myleetcode
8+
9+
FileName: 1544-MakeTheStringGreat
10+
11+
Difficulty: Easy
12+
13+
Desc:
14+
15+
Tag:
16+
17+
See:
18+
19+
"""
20+
21+
22+
class Solution:
23+
def makeGood(self, s: str) -> str:
24+
"""
25+
Runtime: 91 ms, faster than 8.21%
26+
Memory Usage: 13.9 MB, less than 15.06%
27+
1 <= s.length <= 100
28+
s contains only lower and upper case English letters.
29+
"""
30+
s = list(s)
31+
cur, pre = len(s), 0
32+
while cur != pre:
33+
pre = cur
34+
i = 0
35+
while i < len(s) - 1:
36+
if s[i] != s[i + 1] and s[i].lower() == s[i + 1].lower():
37+
s.pop(i)
38+
s.pop(i)
39+
else:
40+
i += 1
41+
cur = len(s)
42+
return ''.join(s)
43+
44+
45+
def test():
46+
assert Solution().makeGood(s="leEeetcode") == "leetcode"
47+
assert Solution().makeGood(s="abBAcC") == ""
48+
49+
50+
if __name__ == '__main__':
51+
test()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /