标签:interview
A balanced tree?
http://en.wikipedia.org/wiki/Self-balancing_binary_search_tree
Iterate the tree, track root-distance for all leaf nodes?
boolean isBalanceTree(Node root) { List<Integer> leafDis = initList(); visit(root, 0, leafDis); return max(leafDis) - min(leafDis) > 1; } private void visit(Node n, int curDis, List<Integer> leafDis) { if (n.childrean == null) leafDis.add(curDis); for (Node child : n.children) { visit(child, curDis + 1, leafDis); } }
标签:interview
原文地址:http://7371901.blog.51cto.com/7361901/1583039