We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1972d20 commit 662dca4Copy full SHA for 662dca4
c/678-Valid-Parenthesis-String.c
@@ -0,0 +1,35 @@
1
+/*
2
+ Time: O(n)
3
+ Space: O(1)
4
+*/
5
+
6
+bool checkValidString(char * s) {
7
+ int n = strlen(s);
8
9
+ int balanced = 0;
10
+ for (int i=0; i<n; i++) {
11
+ if (s[i] == '(' || s[i] == '*')
12
+ balanced++;
13
+ else
14
+ balanced--;
15
16
+ if (balanced < 0)
17
+ return false;
18
+ }
19
20
+ if (balanced == 0)
21
+ return true;
22
23
+ balanced = 0;
24
+ for (int i=n-1; i>=0; i--) {
25
+ if (s[i] == ')' || s[i] == '*')
26
27
28
29
30
31
32
33
34
35
+}
0 commit comments