/**
* @param {string} s
* @return {boolean}
*/
var checkValidString = function(s) {
const record=[];
let cache=[];
for(let i=0;i<s.length;i++){
if(!s[i]) continue;
if(s[i]==='*') cache.push(i);
if(s[i]==='(') record.push(i);
if(s[i]===')'){
if(!record.length){
if(!cache.length) return false;
cache.pop();
}
else record.pop();
}
}
const temp=[];
let j=0,k=0;
for(let i=0;i<s.length;i++){
if(i===record[j]){
temp.push(i);
j++;
}
else if(i===cache[k]){
temp.pop();
k++;
}
}
return !temp.length;
};
【leetcode】有效的括号字符串 hash
最新推荐文章于 2024-07-22 16:27:42 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)