Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class IncorrectSolution {
- public ArrayList<Integer> inorderTraversal(TreeNode A) {
- ArrayList<Integer> list = new ArrayList<>();
- Stack<TreeNode> stack = new Stack<>();
- stack.push(A);
- while(!stack.isEmpty()){
- TreeNode temp = stack.pop();
- if(temp.left != null){
- stack.push(temp);
- stack.push(temp.left);
- }else{
- list.add(temp.val);
- if(temp.right != null){
- stack.push(temp.right);
- }
- }
- }
- return list;
- }
- }
Add Comment
Please, Sign In to add comment