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 ce3335a

Browse files
author
Victor
authored
replace while with for.
1 parent 8a61152 commit ce3335a

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

‎32. Longest Valid Parentheses.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ int longestValidParentheses(char* s) {
2020
v = malloc(l * sizeof(int));
2121
//assert(v);
2222

23-
i=0; n = 0;
24-
while (i < l) {
23+
n = 0;
24+
for (i =0; i< l; i++) {
2525
if (s[i] == '(') {
2626
v[i] = 1;
2727
n ++;
@@ -33,12 +33,10 @@ int longestValidParentheses(char* s) {
3333
v[i] = 0;
3434
}
3535
}
36-
i ++;
3736
}
3837

39-
i = l; n = 0;
40-
while (i > 0) {
41-
i --;
38+
n = 0;
39+
for (i = l - 1; i >= 0; i --) {
4240
if (s[i] == ')') {
4341
if (v[i]) {
4442
n ++;
@@ -52,16 +50,15 @@ int longestValidParentheses(char* s) {
5250
}
5351
}
5452

55-
i=1; n = 0; max = 0;
56-
while (i < l) {
53+
n = 0; max = 0;
54+
for (i =1; i< l; i++) {
5755
if (v[i]) {
5856
v[i] = v[i - 1] + 1;
5957

6058
if (max < v[i]) {
6159
max = v[i];
6260
}
6361
}
64-
i ++;
6562
}
6663

6764
free(v);

0 commit comments

Comments
(0)

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