Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f418cb8

Browse files
committedApr 18, 2025
Add solution #1544
1 parent d05e49b commit f418cb8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,357 LeetCode solutions in JavaScript
1+
# 1,358 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1179,6 +1179,7 @@
11791179
1540|[Can Convert String in K Moves](./solutions/1540-can-convert-string-in-k-moves.js)|Medium|
11801180
1541|[Minimum Insertions to Balance a Parentheses String](./solutions/1541-minimum-insertions-to-balance-a-parentheses-string.js)|Medium|
11811181
1542|[Find Longest Awesome Substring](./solutions/1542-find-longest-awesome-substring.js)|Hard|
1182+
1544|[Make The String Great](./solutions/1544-make-the-string-great.js)|Easy|
11821183
1550|[Three Consecutive Odds](./solutions/1550-three-consecutive-odds.js)|Easy|
11831184
1551|[Minimum Operations to Make Array Equal](./solutions/1551-minimum-operations-to-make-array-equal.js)|Medium|
11841185
1566|[Detect Pattern of Length M Repeated K or More Times](./solutions/1566-detect-pattern-of-length-m-repeated-k-or-more-times.js)|Easy|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 1544. Make The String Great
3+
* https://leetcode.com/problems/make-the-string-great/
4+
* Difficulty: Easy
5+
*
6+
* Given a string s of lower and upper case English letters.
7+
*
8+
* A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:
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
13+
* remove them. You can keep doing this until the string becomes good.
14+
*
15+
* Return the string after making it good. The answer is guaranteed to be unique under the given
16+
* constraints.
17+
*
18+
* Notice that an empty string is also good.
19+
*/
20+
21+
/**
22+
* @param {string} s
23+
* @return {string}
24+
*/
25+
var makeGood = function(s) {
26+
const stack = [];
27+
28+
for (const char of s) {
29+
const lastChar = stack[stack.length - 1];
30+
if (lastChar && ((char.toLowerCase() === lastChar.toLowerCase()) && (char !== lastChar))) {
31+
stack.pop();
32+
} else {
33+
stack.push(char);
34+
}
35+
}
36+
37+
return stack.join('');
38+
};

0 commit comments

Comments
 (0)
Please sign in to comment.