leetcode下载-Leetcode-practice:力扣C++

时间:2021-06-29 19:56:55
【文件属性】:
文件名称:leetcode下载-Leetcode-practice:力扣C++
文件大小:35KB
文件格式:ZIP
更新时间:2021-06-29 19:56:55
系统开源 leetcode下载 Leetcode 100Top-like 字符串 题目: 题目描述: 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。 注意空字符串可被认为是有效字符串。 来源:力扣(LeetCode) 题目思路: 利用stack存储新来字符为 '(','{','['情况,对其他的字符进行匹配判断,不匹配则为false,若为有效的括号,最终栈应该为空 代码: bool isValid(string s) { stack _stack; int length=s.size(); for(int i{0};i<length;++i){ if(s[i]=='(' || s[i]=='{' || s[i]=='[') {_stack.push(s[i]);continue;} if(_stack.empty()) return false; if((s[i]==')' && _stack.top()=='(') || (s[i]=='}' &&
【文件预览】:
Leetcode-practice-master
----pic()
--------productExceptSelf1.png(5KB)
--------productExceptSelf2.png(21KB)
----README.md(40KB)

网友评论