Skip to content

Commit ab2111d

Browse files
author
baochau.dinh
committed
js-concepts: leetcode prob.678 - Valid parenthesis string with stars
1 parent 6fa456c commit ab2111d

File tree

1 file changed

+22
-0
lines changed
  • LeetCode/678. Valid Parenthesis String

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var checkValidString = function(s) {
2+
let diff = 0;
3+
for (let i = 0; i < s.length; i++) {
4+
if (s[i] === '(' || s[i] === '*') diff++
5+
else diff--
6+
if (diff < 0) return false;
7+
}
8+
if (diff === 0) return true
9+
10+
diff = 0;
11+
for (let i = s.length - 1; i >= 0; i--) {
12+
if (s[i] === ')' || s[i] === '*') diff++
13+
else diff--
14+
if (diff < 0) return false;
15+
}
16+
return true;
17+
};
18+
19+
var checkValidStringV2 = function(s) {
20+
let diff = 0;
21+
let first = 0, second = s.length - 1;
22+
}

0 commit comments

Comments
 (0)