Created
June 7, 2014 16:05
-
-
Save walkingtospace/d555432169f244df5489 to your computer and use it in GitHub Desktop.
inorder Traversal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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