share my solution by traversing the tree "iteratively"

class Solution { public int pathSum(int[] nums) { //corner if (nums.length == 0) { return 0; } //store the node(represent by level and col #) and its corresponding path sum which is the sum of path from root to this node Map<Integer, Integer> map = new HashMap<>(); int sum = 0; for (int num : nums) { int level = num/100; int value = num%10; int key = (num - value)/10; int col = (num%100 - value)/10; if (level == 1) { map.put(11, value); } else { int upperKey = (level-1) * 10 + (col + 1)/2; map.put(key, value + map.get(upperKey)); } } //if the node has no children, then add the path sum for (int key : map.keySet()) { int level = key/10; int col = key%10; int left = 10* (level+1) + col * 2 - 1; int right = 10* (level+1) + col * 2 ; if (!map.containsKey(left) && !map.containsKey(right)) { sum += map.get(key); } } return sum; } }Path Sum IV