Skip to content

Commit c5cc12a

Browse files
refactor 538
1 parent 04c6f41 commit c5cc12a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Your ideas/fixes/algorithms are more than welcome!
111111
|541|[Reverse String II](https://leetcode.com/problems/reverse-string-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_541.java) | O(n) |O(1) | Easy | String
112112
|540|[Single Element in a Sorted Array](https://leetcode.com/problems/single-element-in-a-sorted-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_540.java) | O(n) |O(1) | Medium |
113113
|539|[Minimum Time Difference](https://leetcode.com/problems/minimum-time-difference/)|[Solution](../master/src/main/java/com/fishercoder/solutions/MinimumTimeDifference.java) | O(n) |O(1) | Medium | String
114-
|538|[Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_538.java) | O(n) |O(h) | Medium | Tree
114+
|538|[Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_538.java) | O(n) |O(h) | Easy | Tree
115115
|537|[Complex Number Multiplication](https://leetcode.com/problems/complex-number-multiplication/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_537.java) | O(1) |O(1) | Medium | Math, String
116116
|536|[Construct Binary Tree from String](https://leetcode.com/problems/construct-binary-tree-from-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_536.java) | O(n) |O(h) | Medium | Recursion, Stack
117117
|535|[Encode and Decode TinyURL](https://leetcode.com/problems/encode-and-decode-tinyurl/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_535.java) | O(1) |O(n) | Medium | Design

Diff for: src/main/java/com/fishercoder/solutions/_538.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@
2929
public class _538 {
3030

3131
public static class BSTSolution {
32-
/**reference: https://discuss.leetcode.com/topic/83455/java-recursive-o-n-time/13
33-
*
34-
* A reversed version of inorder traversal: right -> root -> left*/
32+
/**
33+
* Traverse in this order: right -> root -> left
34+
*/
3535
public TreeNode convertBST(TreeNode root) {
3636
dfs(root, 0);
3737
return root;
3838
}
3939

4040
private int dfs(TreeNode root, int val) {
41-
if (root == null) return val;
41+
if (root == null) {
42+
return val;
43+
}
4244
int right = dfs(root.right, val);
4345
root.val += right;
4446
int left = dfs(root.left, root.val);
@@ -85,4 +87,5 @@ private void putNodeToList(List<Integer> list, TreeNode root) {
8587
if (root.right != null) putNodeToList(list, root.right);
8688
}
8789
}
88-
}
90+
91+
}

0 commit comments

Comments
 (0)