Skip to content

Commit e1f2fa0

Browse files
Update 1544-make-the-string-great.md
1 parent cfd935c commit e1f2fa0

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

dsa-solutions/lc-solutions/1500-1599/1544-make-the-string-great.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@ id: make-the-string-great
33
title: Make The String Great (Leetcode)
44
sidebar_label: 1544-MakeTheStringGreat
55
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.
176
---
187

198
## Problem Description
@@ -42,7 +31,7 @@ Notice that an empty string is also good.
4231

4332
#### Example 1
4433

45-
- **Input:** $s = "leEeetcode"$
34+
- **Input:** s = "leEeetcode"
4635
- **Output:** $"leetcode"$
4736
- **Explanation:** In the first step, either you choose $i = 1$ or $i = 2$, both will result $"leEeetcode"$ to be reduced to $"leetcode"$.
4837

@@ -52,20 +41,20 @@ Notice that an empty string is also good.
5241
- **Input:** $s = "abBAcC"$
5342
- **Output:** $""$
5443
- **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" --> ""
5746

5847
#### Example 2
5948

60-
- **Input:** $s = "s"$
61-
- **Output:** $"s"$
49+
- **Input:** s = "s"
50+
- **Output:** "s"
6251

6352

6453
### Constraints
6554

6655

6756
- $1 <= s.length <= 100$
68-
- $s$ contains only lower and upper case English letters.
57+
- s contains only lower and upper case English letters.
6958

7059

7160

@@ -180,4 +169,4 @@ public:
180169

181170
### Conclusion
182171

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

Comments
 (0)