Skip to content

Commit 2664f27

Browse files
edit 156
1 parent 3debb9e commit 2664f27

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ Your ideas/fixes/algorithms are more than welcome!
391391
|159|[Longest Substring with At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/LongestSubstringwithAtMostTwoDistinctCharacters.java)| O(n)|O(1) | Hard| String, Sliding Window
392392
|158|[Read N Characters Given Read4 II - Call multiple times](https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/)|[Solution](../master/src/main/java/com/fishercoder/solutions/ReadNCharactersGivenRead4IICallMultipleTimes.java)| O(n)|O(1) | Hard|
393393
|157|[Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4/)|[Solution](../master/src/main/java/com/fishercoder/solutions/ReadNCharactersGivenRead4.java)| O(n)|O(1) | Easy|
394-
|156|[Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down/)|[Solution](../master/src/main/java/com/fishercoder/solutions/BinaryTreeUpsideDown.java)| O(n)|O(h) | Medium| Tree, Recursion
394+
|156|[Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_156.java)| O(n)|O(h) | Medium| Tree, Recursion
395395
|155|[Min Stack](https://leetcode.com/problems/min-stack/)|[Solution](../master/src/main/java/com/fishercoder/solutions/MinStack.java)| O(1)|O(n) | Easy| Stack
396396
|154|[Find Minimum in Rotated Sorted Array II](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_154.java)| O(logn)|O(1) | Hard| Array, Binary Search
397397
|153|[Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_153.java)| O(logn)|O(1) | Medium| Array, Binary Search

src/main/java/com/fishercoder/solutions/BinaryTreeUpsideDown.java src/main/java/com/fishercoder/solutions/_156.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
import com.fishercoder.common.classes.TreeNode;
44

55
/**
6-
* Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the original right nodes turned into left leaf nodes. Return the new root.
6+
* Given a binary tree where all the right nodes are either leaf nodes with a sibling
7+
* (a left node that shares the same parent node) or empty,
8+
* flip it upside down and turn it into a tree where the original right nodes turned into left leaf nodes. Return the new root.
79
810
For example:
911
Given a binary tree {1,2,3,4,5},
10-
1
11-
/ \
12-
2 3
13-
/ \
14-
4 5
12+
1
13+
/ \
14+
2 3
15+
/ \
16+
4 5
1517
return the root of the binary tree [4,5,2,#,#,3,1].
16-
4
17-
/ \
18-
5 2
19-
/ \
20-
3 1
18+
4
19+
/ \
20+
5 2
21+
/ \
22+
3 1
2123
confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ.
2224
*/
23-
public class BinaryTreeUpsideDown {
25+
public class _156 {
2426

25-
public TreeNode upsideDownBinaryTree(TreeNode root)
26-
{
27+
public TreeNode upsideDownBinaryTree(TreeNode root) {
2728
if (root == null || root.left == null && root.right == null)
2829
return root;
2930
TreeNode newRoot = upsideDownBinaryTree(root.left);

0 commit comments

Comments
 (0)