I got passed a neatly designed iteration solution that is borrowed from another post. It pushes each node two times into the stack. When we pop up a node with same value as the next node in the stack, it is going down the tree. Otherwise, it is going up. I see that this method will fail if some duplicate values exist on the tree. However, it passed around the OJ tests. I guess there is not any such special case in the tests. For example: {2, 2, #, 2, #, #, #}. Anyway, it is good to know such a solution there.

```
class Solution {
public:
vector<int> postorderTraversal(TreeNode *root) {
vector<int> res;
stack<TreeNode *> s;
if (!root) return res;
s.push(root);
s.push(root);
while (!s.empty()) {
TreeNode * cur = s.top();
s.pop();
if (!s.empty() && cur->val == s.top()->val) {
if (cur->right) s.push(cur->right), s.push(cur->right);
if (cur->left) s.push(cur->left), s.push(cur->left);
}
else
res.push_back(cur->val);
}
return res;
}
};
```