您的位置:首页 > 其它

Leetcode 之Length of Last Word(38)

2016-05-26 15:34 435 查看
bool isValid(const string& s)
{
string left = "([{";
string right = ")]}";
stack<char> stk;

for (auto c : s)
{
if (left.find(c) != string::npos)
{
stk.push(c);
}
else
{
if (stk.empty() || stk.top() != left[right.find(c)])
return false;
else
stk.pop();
}
}

return stk.empty();
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: