File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,173 LeetCode solutions in JavaScript
1
+ # 1,174 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
922
922
1186|[ Maximum Subarray Sum with One Deletion] ( ./solutions/1186-maximum-subarray-sum-with-one-deletion.js ) |Medium|
923
923
1187|[ Make Array Strictly Increasing] ( ./solutions/1187-make-array-strictly-increasing.js ) |Hard|
924
924
1189|[ Maximum Number of Balloons] ( ./solutions/1189-maximum-number-of-balloons.js ) |Easy|
925
+ 1190|[ Reverse Substrings Between Each Pair of Parentheses] ( ./solutions/1190-reverse-substrings-between-each-pair-of-parentheses.js ) |Medium|
925
926
1200|[ Minimum Absolute Difference] ( ./solutions/1200-minimum-absolute-difference.js ) |Easy|
926
927
1206|[ Design Skiplist] ( ./solutions/1206-design-skiplist.js ) |Hard|
927
928
1207|[ Unique Number of Occurrences] ( ./solutions/1207-unique-number-of-occurrences.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1190. Reverse Substrings Between Each Pair of Parentheses
3
+ * https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given a string s that consists of lower case English letters and brackets.
7
+ *
8
+ * Reverse the strings in each pair of matching parentheses, starting from the innermost one.
9
+ *
10
+ * Your result should not contain any brackets.
11
+ */
12
+
13
+ /**
14
+ * @param {string } s
15
+ * @return {string }
16
+ */
17
+ var reverseParentheses = function ( s ) {
18
+ const stack = [ [ ] ] ;
19
+
20
+ for ( const char of s ) {
21
+ if ( char === '(' ) {
22
+ stack . push ( [ ] ) ;
23
+ } else if ( char === ')' ) {
24
+ const reversed = stack . pop ( ) . reverse ( ) ;
25
+ stack [ stack . length - 1 ] . push ( ...reversed ) ;
26
+ } else {
27
+ stack [ stack . length - 1 ] . push ( char ) ;
28
+ }
29
+ }
30
+
31
+ return stack [ 0 ] . join ( '' ) ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments