Skip to content

Commit 64cdbb3

Browse files
committed
Add solution #1111
1 parent 5189612 commit 64cdbb3

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,140 LeetCode solutions in JavaScript
1+
# 1,141 LeetCode solutions in JavaScript
22

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

@@ -884,6 +884,7 @@
884884
1108|[Defanging an IP Address](./solutions/1108-defanging-an-ip-address.js)|Easy|
885885
1109|[Corporate Flight Bookings](./solutions/1109-corporate-flight-bookings.js)|Medium|
886886
1110|[Delete Nodes And Return Forest](./solutions/1110-delete-nodes-and-return-forest.js)|Medium|
887+
1111|[Maximum Nesting Depth of Two Valid Parentheses Strings](./solutions/1111-maximum-nesting-depth-of-two-valid-parentheses-strings.js)|Medium|
887888
1122|[Relative Sort Array](./solutions/1122-relative-sort-array.js)|Easy|
888889
1123|[Lowest Common Ancestor of Deepest Leaves](./solutions/1123-lowest-common-ancestor-of-deepest-leaves.js)|Medium|
889890
1137|[N-th Tribonacci Number](./solutions/1137-n-th-tribonacci-number.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* 1111. Maximum Nesting Depth of Two Valid Parentheses Strings
3+
* https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/
4+
* Difficulty: Medium
5+
*
6+
* A string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")"
7+
* characters only, and:
8+
* - It is the empty string, or
9+
* - It can be written as AB (A concatenated with B), where A and B are VPS's, or
10+
* - It can be written as (A), where A is a VPS.
11+
*
12+
* We can similarly define the nesting depth depth(S) of any VPS S as follows:
13+
* - depth("") = 0
14+
* - depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's
15+
* - depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
16+
*
17+
* For example, "", "()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2),
18+
* and ")(" and "(()" are not VPS's.
19+
*
20+
* Given a VPS seq, split it into two disjoint subsequences A and B, such that A and B are VPS's
21+
* (and A.length + B.length = seq.length).
22+
*
23+
* Now choose any such A and B such that max(depth(A), depth(B)) is the minimum possible value.
24+
*
25+
* Return an answer array (of length seq.length) that encodes such a choice of A and B:
26+
* answer[i] = 0 if seq[i] is part of A, else answer[i] = 1. Note that even though multiple
27+
* answers may exist, you may return any of them.
28+
*/
29+
30+
/**
31+
* @param {string} seq
32+
* @return {number[]}
33+
*/
34+
var maxDepthAfterSplit = function(seq) {
35+
const result = new Array(seq.length);
36+
let depth = 0;
37+
38+
for (let i = 0; i < seq.length; i++) {
39+
if (seq[i] === '(') {
40+
result[i] = depth++ % 2;
41+
} else {
42+
result[i] = --depth % 2;
43+
}
44+
}
45+
46+
return result;
47+
};

0 commit comments

Comments
 (0)