Skip to content

Instantly share code, notes, and snippets.

@walkingtospace
Created June 7, 2014 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkingtospace/d555432169f244df5489 to your computer and use it in GitHub Desktop.
Save walkingtospace/d555432169f244df5489 to your computer and use it in GitHub Desktop.
inorder Traversal
https://oj.leetcode.com/problems/binary-tree-inorder-traversal/
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> result;
vector<int> inorderTraversal(TreeNode *root) {
if( root != NULL ) {
inorderTraversal(root->left);
result.push_back(root->val);
inorderTraversal(root->right);
return result;
} else {
return result;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment