Skip to content

Commit 9560417

Browse files
committed
sum of all left leaves problem and solution
1 parent b25e338 commit 9560417

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎src/problems/Easy.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,4 +627,5 @@ Implement the "paint fill" function that one might see on many image editing pro
627627
That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color,
628628
fill in the surrounding area until the color changes from the original color.
629629

630-
90)
630+
90)Find sum of all left leaves in a given Binary Tree
631+
Given a Binary Tree, find sum of all left leaves in it.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package problems.easy;
2+
3+
import problems.utils.TreeNode;
4+
5+
/**
6+
* Created by sherxon on 5/21/17.
7+
*/
8+
public class FindSumOfALlLeftLeavesBT {
9+
10+
public int sumOfLeftLeaves(TreeNode root) {
11+
if (root == null) {
12+
return 0;
13+
}
14+
return sum(root, root);
15+
}
16+
17+
private int sum(TreeNode root, TreeNode child) {
18+
if (child == null) {
19+
return 0;
20+
}
21+
if (child.left == null && child.right == null && child == root.left) {
22+
return child.val;
23+
}
24+
return sum(child, child.left) + sum(child, child.right);
25+
26+
}
27+
}

‎src/triplebyte/Board.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package triplebyte;
22

33
import java.util.Scanner;
4+
import java.util.concurrent.CountDownLatch;
45

56
/**
67
* Created by sherxon on 5/17/17.
78
*/
89
public class Board {
910

1011
static char[][] a = new char[3][3];
12+
CountDownLatch countDownLatch = new CountDownLatch(10);
1113

1214
public static void main(String[] args) {
1315
clear();

0 commit comments

Comments
 (0)