Skip to content

Commit

Permalink
Time: 15 ms (83.4%), Space: 45.5 MB (87.55%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Jan 12, 2025
1 parent 9ff7ebf commit fdc7d70
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public boolean canBeValid(String s, String locked) {
int n = s.length();
if (n % 2 != 0) return false;
int min = 0, max = 0;
for (int i = 0; i < n; i++) {
boolean open = s.charAt(i) == '(';
boolean unlocked = locked.charAt(i) == '0';
min += (!open || unlocked) ? -1 : 1;
max += (open || unlocked) ? 1 : -1;

if (max < 0) return false;
min = Math.max(min, 0);
}
return min == 0;
}
}

0 comments on commit fdc7d70

Please sign in to comment.