标签:style class false bool ack || ring ret else
栈的教科书式套路。
class Solution { public: bool isValid(string s) { stack<char> a; int n=s.length(); for (int i=0;i<n;i++){ if (s[i]==‘(‘||s[i]==‘[‘||s[i]==‘{‘) a.push(s[i]); else { if (a.empty()) return false; char t=a.top(); a.pop(); if (s[i]==‘}‘&&t!=‘{‘) return false; if (s[i]==‘)‘&&t!=‘(‘) return false; if (s[i]==‘]‘&&t!=‘[‘) return false; } } if (a.empty()) return true; else return false; } };
LeetCode 20. Valid Parentheses
标签:style class false bool ack || ring ret else
原文地址:https://www.cnblogs.com/travelller/p/9462278.html