| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/feixiangcode/algorithm/master/Week_01/id_119/LeetCode_20_119.cpp | [Back] [Original] |
class Solution {
public:
bool isValid(string s) {
if (s.size() == 0) {
return true;
}
std::unordered_map hash = {
{'(', ')'},
{'[', ']'},
{'{', '}'},
};
std::unordered_map::iterator iter;
std::stack test;
for (string::size_type i=0;isecond) {
test.pop();
} else if (hash.find(s[i]) != hash.end()) {
test.push(s[i]);
} else {
return false;
}
} else {
if (hash.find(s[i]) != hash.end()) {
test.push(s[i]);
} else {
return false;
}
}
}
return test.empty();
}
};
| Web Proxy Viewer | New URL | Original Page |