We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
leetcode: 22. Binary Tree Inorder Traversal
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<int> inorderTraversal(TreeNode *root) { vector<int> res; if (!root) return res; TreeNode *cur, *pre; cur = root; while (cur) { if (!cur->left) { res.push_back(cur->val); cur = cur->right; } else { pre = cur->left; while (pre->right && pre->right != cur) pre = pre->right; if (!pre->right) { pre->right = cur; cur = cur->left; } else { pre->right = NULL; res.push_back(cur->val); cur = cur->right; } } } return res; } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
leetcode: 22. Binary Tree Inorder Traversal
The text was updated successfully, but these errors were encountered: