Skip to content

Commit 1e71627

Browse files
committed
Time: 3 ms (100%), Space: 18.3 MB (22.97%) - LeetHub
1 parent b657a56 commit 1e71627

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# time complexity: O(n)
2+
# space complexity: O(1)
3+
class Solution:
4+
def minLengthAfterRemovals(self, s: str) -> int:
5+
return abs(s.count('b') - s.count('a'))
6+
7+
8+
s = "aabbab"
9+
print(Solution().minLengthAfterRemovals(s))
10+
s = "aaaa"
11+
print(Solution().minLengthAfterRemovals(s))
12+
s = "aaabb"
13+
print(Solution().minLengthAfterRemovals(s))

0 commit comments

Comments
 (0)