Skip to content

Commit

Permalink
feat: LC-0678: Valid Parenthesis String
Browse files Browse the repository at this point in the history
add java solution for leetcode problem 678 - Valid Parenthesis String
  • Loading branch information
galaumang committed Oct 2, 2023
1 parent 67ce3f7 commit 4f172e8
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dsalgo.string;

public class LC0678_ValidParenthesisString {
public boolean checkValidString(String s) {
int lo = 0, hi = 0;
for (char c : s.toCharArray()) {
lo += c == '(' ? 1 : -1;
hi += c != ')' ? 1 : -1;
if (hi < 0)
break;
lo = Math.max(lo, 0);
}
return lo == 0;
}
}

0 comments on commit 4f172e8

Please sign in to comment.