t******i 发帖数: 35 | 1 下面代码好像可以跑过几个case, 就是用两个 minStack, maxStack,在 traverse
list
同时判断是否是valid BST.
bool listValidBSTHelper(stack &minsk, stack &maxsk, list::
iterator &it, list &l) {
if (it == l.end()) return true;
if (minsk.empty() || maxsk.empty()) return false;
if (*it <= minsk.top() || *it >= maxsk.top()) {
int val = maxsk.top();
maxsk.pop();
minsk.push(val);
return listValidBSTHelper(minsk, maxsk, it, l);
}
maxsk.push(*it);
it++;
if ... 阅读全帖 |
|