示例#1
0
 public void RecoverTree(TreeNode root)
 {
     if (root != null) {
         goTravers(root);
         var tmp = ReverseList[0].val;
         ReverseList[0].val = ReverseList[ReverseList.Count - 1].val;
         ReverseList[ReverseList.Count - 1].val = tmp;
     }
 }
示例#2
0
 public void goTravers(TreeNode node)
 {
     if (node.left != null) {
         goTravers(node.left);
     }
     if (CurrNode != null && node.val < CurrNode.val) {
         ReverseList.Add(CurrNode);
         ReverseList.Add((node));
     }
     CurrNode = node;
     if (node.right != null) {
         goTravers(node.right);
     }
 }