MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / checkValidString

Function checkValidString

javascript/0678-valid-parenthesis-string.js:5–31  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

3 * @return {boolean}
4 */
5var checkValidString = function (s) {
6 var leftMin = 0;
7 var leftMax = 0;
8
9 for (var c of s) {
10 if (c === '(') {
11 leftMin++;
12 leftMax++;
13 } else if (c === ')') {
14 leftMin--;
15 leftMax--;
16 } else {
17 leftMin--;
18 leftMax++;
19 }
20
21 if (leftMax < 0) {
22 return false;
23 }
24
25 if (leftMin < 0) {
26 leftMin = 0;
27 }
28 }
29
30 return leftMin === 0;
31};
32
33/**
34 * https://leetcode.com/problems/valid-parenthesis-string/

Callers

nothing calls this directly

Calls 5

isStarFunction · 0.85
isOpenedFunction · 0.85
isClosedFunction · 0.85
isDPFunction · 0.85
checkFunction · 0.70

Tested by

no test coverage detected