File tree 1 file changed +9
-3
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,9 @@ public class _103 {
33
33
public List <List <Integer >> zigzagLevelOrder (TreeNode root ) {
34
34
Queue <TreeNode > q = new LinkedList ();
35
35
List <List <Integer >> levels = new ArrayList ();
36
- if (root == null ) return levels ;
36
+ if (root == null ) {
37
+ return levels ;
38
+ }
37
39
q .offer (root );
38
40
boolean forward = true ;
39
41
while (!q .isEmpty ()) {
@@ -42,8 +44,12 @@ public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
42
44
for (int i = 0 ; i < size ; i ++) {
43
45
TreeNode curr = q .poll ();
44
46
level .add (curr .val );
45
- if (curr .left != null ) q .offer (curr .left );
46
- if (curr .right != null ) q .offer (curr .right );
47
+ if (curr .left != null ) {
48
+ q .offer (curr .left );
49
+ }
50
+ if (curr .right != null ) {
51
+ q .offer (curr .right );
52
+ }
47
53
}
48
54
if (forward ) {
49
55
forward = false ;
You can’t perform that action at this time.
0 commit comments