GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Mirror BST

Suhas S Englisch 1 Karte

Karten in diesem Stapel (1)

  1. 1Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1class Solution {
    public TreeNode invertTree(TreeNode root) {
    if(root ==null) {
    return root;
    }
    root=invertOperation(root,root.left,root.right);
    return root;
    }
    public TreeNode invertOperation(TreeNode root,TreeNode left,TreeNode right) {
    if(root ==null) {
    return root;
    }
    if(left!=null) {
    invertOperation(left,left.left,left.right);
    }
    TreeNode temp=new TreeNode(0);
    temp=root.left;//temp=1
    root.left=root.right;//left=3
    root.right=temp;//right=1
    if(right!=null) {
    invertOperation(right,right.left,right.right);
    }
    return root;
    }
    }

Informationen

Beschreibung
Karteikarten am Mirror BST, erstellt von Suhas S am 12/05/2018.
Erstellt von
Suhas S
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck