Re: [閒聊] 每日leetcode

作者: dont   2025-01-12 11:03:51
2116. Check if a Parentheses String Can Be Valid
## 思路
記錄還沒配對的括號個數 open
把locked==0的也當作 `(`
如果遇到配對不了的括號 就回傳FALSE
兩個方向各掃一遍
## Code
```cpp
class Solution {
public:
bool canBeValid(string s, string locked) {
int n = s.size();
if (n & 1) return false;
int open = 0;
for (int i=0; i<n; ++i) {
if (locked[i] == '0' || s[i] == '(') {
++open;
} else if (open == 0) {
return false;
} else {
作者: sustainer123 (caster)   2025-01-12 12:17:00
不用考慮AB喔?

Links booklink

Contact Us: admin [ a t ] ucptt.com