MCPcopy
hub / github.com/qiyuangong/leetcode / sumOfLeftLeaves

Method sumOfLeftLeaves

java/404_Sum_of_Left_Leaves.java:24–40  ·  view source on GitHub ↗
(TreeNode root)

Source from the content-addressed store, hash-verified

22 } */
23
24 public int sumOfLeftLeaves(TreeNode root) {
25 int res = 0;
26 Stack<TreeNode> stack = new Stack<>();
27 stack.push(root);
28 while (!stack.isEmpty()) {
29 TreeNode node = stack.pop();
30 if (node != null) {
31 if (node.left != null
32 && node.left.left == null
33 && node.left.right == null)
34 res += node.left.val;
35 stack.push(node.right);
36 stack.push(node.left);
37 }
38 }
39 return res;
40 }
41}

Callers

nothing calls this directly

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected