File tree 2 files changed +40
-1
lines changed
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,357 LeetCode solutions in JavaScript
1
+ # 1,358 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1179
1179
1540|[ Can Convert String in K Moves] ( ./solutions/1540-can-convert-string-in-k-moves.js ) |Medium|
1180
1180
1541|[ Minimum Insertions to Balance a Parentheses String] ( ./solutions/1541-minimum-insertions-to-balance-a-parentheses-string.js ) |Medium|
1181
1181
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|
1182
1183
1550|[ Three Consecutive Odds] ( ./solutions/1550-three-consecutive-odds.js ) |Easy|
1183
1184
1551|[ Minimum Operations to Make Array Equal] ( ./solutions/1551-minimum-operations-to-make-array-equal.js ) |Medium|
1184
1185
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|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments