标签:return span com ima 节点 alt res air null
class Solution { public int countPairs(TreeNode root, int distance) { dfs(root,0,distance); return res; } private int res = 0; public List<Integer> dfs(TreeNode root,int level, int distance) { List<Integer> list = new ArrayList<>(); if(root == null) return list; if(root.left == null && root.right == null) list.add(level); List<Integer> left = new ArrayList<>(dfs(root.left,level+1,distance)); List<Integer> right = new ArrayList<>(dfs(root.right,level+1,distance)); for(int l : left) { for(int r : right) { if(l - level + r - level <= distance) res++; } } list.addAll(left); list.addAll(right); return list; } }
标签:return span com ima 节点 alt res air null
原文地址:https://www.cnblogs.com/yonezu/p/13384269.html