Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e17777

Browse files
Changes for Parantesis
1 parent cc4ba03 commit 9e17777

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var checkValidString = function (s) {
6+
let m = {};
7+
return checkValidStringHelper(s, 0, 0, m);
8+
};
9+
10+
var checkValidStringHelper = function (s, i, k, m) {
11+
if (i == s.length && k == 0) {
12+
return true;
13+
} else if (k < 0 || i == s.length) {
14+
return false;
15+
}
16+
17+
if (m.hasOwnProperty(i + "-" + k)) {
18+
return m[i + "-" + k];
19+
}
20+
let isValid = false;
21+
if (s[i] == '(') {
22+
isValid = checkValidStringHelper(s, i + 1, k + 1, m);
23+
} else if (s[i] == ')') {
24+
isValid = checkValidStringHelper(s, i + 1, k - 1, m);
25+
} else {
26+
let l1 = checkValidStringHelper(s, i + 1, k, m);
27+
let l2 = checkValidStringHelper(s, i + 1, k + 1, m);
28+
let l3 = checkValidStringHelper(s, i + 1, k - 1, m);
29+
isValid = l1 || l2 || l3;
30+
}
31+
m[i + "-" + k] = isValid;
32+
return isValid;
33+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /