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 7d34f37

Browse files
committedApr 5, 2025
Add solution #1190
1 parent c381642 commit 7d34f37

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-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,173 LeetCode solutions in JavaScript
1+
# 1,174 LeetCode solutions in JavaScript
22

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

@@ -922,6 +922,7 @@
922922
1186|[Maximum Subarray Sum with One Deletion](./solutions/1186-maximum-subarray-sum-with-one-deletion.js)|Medium|
923923
1187|[Make Array Strictly Increasing](./solutions/1187-make-array-strictly-increasing.js)|Hard|
924924
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|
925926
1200|[Minimum Absolute Difference](./solutions/1200-minimum-absolute-difference.js)|Easy|
926927
1206|[Design Skiplist](./solutions/1206-design-skiplist.js)|Hard|
927928
1207|[Unique Number of Occurrences](./solutions/1207-unique-number-of-occurrences.js)|Easy|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
};

0 commit comments

Comments
 (0)
Please sign in to comment.