You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/1500-1599/1544-make-the-string-great.md
+7-18Lines changed: 7 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -3,17 +3,6 @@ id: make-the-string-great
3
3
title: Make The String Great (Leetcode)
4
4
sidebar_label: 1544-MakeTheStringGreat
5
5
description: Given a string s of lower and upper case English letters.
6
-
7
-
A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:
8
-
9
-
- $0 <= i <= s.length - 2$
10
-
- $s[i]$ is a lower-case letter and $s[i + 1]$ is the same letter but in upper-case or vice-versa.
11
-
12
-
To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.
13
-
14
-
Return the string after making it good. The answer is guaranteed to be unique under the given constraints.
15
-
16
-
Notice that an empty string is also good.
17
6
---
18
7
19
8
## Problem Description
@@ -42,7 +31,7 @@ Notice that an empty string is also good.
42
31
43
32
#### Example 1
44
33
45
-
-**Input:**$s = "leEeetcode"$
34
+
-**Input:** s = "leEeetcode"
46
35
-**Output:** $"leetcode"$
47
36
-**Explanation:** In the first step, either you choose $i = 1$ or $i = 2$, both will result $"leEeetcode"$ to be reduced to $"leetcode"$.
48
37
@@ -52,20 +41,20 @@ Notice that an empty string is also good.
52
41
-**Input:** $s = "abBAcC"$
53
42
-**Output:** $""$
54
43
-**Explanation:** We have many possible scenarios, and all lead to the same answer. For example:</br>
55
-
$"abBAcC"$ --> $"aAcC"$ --> $"cC"$ --> $""$
56
-
$"abBAcC"$ --> $"abBA"$ --> $"aA"$ --> $""$
44
+
"abBAcC" --> "aAcC" --> "cC" --> ""
45
+
"abBAcC" --> "abBA" --> "aA" --> ""
57
46
58
47
#### Example 2
59
48
60
-
-**Input:**$s = "s"$
61
-
-**Output:**$"s"$
49
+
-**Input:** s = "s"
50
+
-**Output:** "s"
62
51
63
52
64
53
### Constraints
65
54
66
55
67
56
- $1 <= s.length <= 100$
68
-
-$s$ contains only lower and upper case English letters.
57
+
-s contains only lower and upper case English letters.
69
58
70
59
71
60
@@ -180,4 +169,4 @@ public:
180
169
181
170
### Conclusion
182
171
183
-
The code efficiently creates a "good" string by removing adjacent pairs of characters where one is the uppercase version of the other. It uses a StringBuilder to store and manipulate the characters, iterating through the input string and checking for adjacent pairs. If such a pair is found, the last character is removed from the StringBuilder; otherwise, the current character is appended. This approach ensures that the resulting string has no adjacent pairs of uppercase-lowercase characters, adhering to the desired output. The time complexity of this approach is $O(n)$, where $n$ is the length of the input string, as each character is processed once. The space complexity is also $O(n)$ due to the storage of the StringBuilder.
172
+
The code efficiently creates a "good" string by removing adjacent pairs of characters where one is the uppercase version of the other. It uses a StringBuilder to store and manipulate the characters, iterating through the input string and checking for adjacent pairs. If such a pair is found, the last character is removed from the StringBuilder; otherwise, the current character is appended. This approach ensures that the resulting string has no adjacent pairs of uppercase-lowercase characters, adhering to the desired output. The time complexity of this approach is $O(n)$, where $n$ is the length of the input string, as each character is processed once. The space complexity is also $O(n)$ due to the storage of the StringBuilder.
0 commit comments