inorder
void inorder(Node* root){
if(root != NULL){
inorder(root->left);
cout<<root->data<<" ";
inorder(root->right);
}
}
inorder
void inorder(Node* root){
if(root != NULL){
inorder(root->left);
cout<<root->data<<" ";
inorder(root->right);
}
}
inorder traversal
class Solution {
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> list = new ArrayList<Integer>();
return dfs(root, list);
}
private List<Integer> dfs(TreeNode root, List<Integer> list)
{
if(root == null)
return list;
list = dfs(root.left, list);
list.add(root.val);
return dfs(root.right,list);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us