class Solution {
public:
void inorder(TreeNode* root, vector& a) {
if (!root) {
return;
}
inorder(root->left, a);
a.push_back(root->val);
inorder(root->right, a);
};
vector<int> inorderTraversal(TreeNode* root) {
vector<int> a;
if(root!=NULL)
{
inorder(root->left,a);
a.push_back(root->val);
inorder(root->right,a);
}
return a;
}
};
class Solution {
public List inorderTraversal(TreeNode root) {
List list = new ArrayList<>();
Stack stack = new Stack<>();
TreeNode cur = root;
while (cur != null || !stack.isEmpty()) {
if (cur != null) {
stack.push(cur);
cur = cur.left;
} else {
cur = stack.pop();
list.add(cur.val);
cur = cur.right;
}
}
return list;
}
}