Guest User

Untitled

a guest
Jun 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public class IncorrectSolution {
  2.  
  3. public ArrayList<Integer> inorderTraversal(TreeNode A) {
  4. ArrayList<Integer> list = new ArrayList<>();
  5. Stack<TreeNode> stack = new Stack<>();
  6. stack.push(A);
  7. while(!stack.isEmpty()){
  8. TreeNode temp = stack.pop();
  9. if(temp.left != null){
  10. stack.push(temp);
  11. stack.push(temp.left);
  12. }else{
  13. list.add(temp.val);
  14. if(temp.right != null){
  15. stack.push(temp.right);
  16. }
  17. }
  18. }
  19. return list;
  20. }
  21.  
  22.  
  23. }
Add Comment
Please, Sign In to add comment