LeetCode: Convert BST to Greater Tree
2017-05-12 11:01
387 查看
利用好BST的特性,解起来并不难
1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */ 10 public class Solution { 11 private int sum = 0; 12 public TreeNode convertBST(TreeNode root) { 13 if (root == null) return null; 14 convertBST(root.right); 15 root.val += sum; 16 sum = root.val; 17 convertBST(root.left); 18 return root; 19 } 20 }
相关文章推荐
- Convert BST to Greater Tree(leetcode)
- 算法分析与设计——LeetCode Problem.538 Convert BST to Greater Tree
- Leetcode 538:Convert BST to Greater Tree
- leetcode[Convert BST to Greater Tree]//待整理多种解法
- LeetCode之Convert BST to Greater Tree(Kotlin)
- LeetCode Convert BST to Greater Tree
- [LeetCode] Convert BST to Greater Tree 将二叉搜索树BST转为较大树
- Leetcode | Convert BST to Greater Tree
- leetcode 538 Convert BST to Greater Tree C++
- LeetCode 538 Convert BST to Greater Tree(二叉树的右中左遍历)
- LeetCode - 538 - Convert BST to Greater Tree
- LeetCode-538 Convert BST to Greater Tree
- LeetCode 538----Convert BST to Greater Tree
- LeetCode Convert BST to Greater Tree
- leetcode(538). Convert BST to Greater Tree
- leetcode(538):Convert BST to Greater Tree
- leetcode: Convert BST to Greater Tree
- Convert BST to Greater Tree
- Convert BST to Greater Tree
- 538. Convert BST to Greater Tree