摘要: LeetCode 跟树结构相关的题目的测试用例中大多是通过String数组来构造树。例如{2,#,3,#,4,#,5,#,6},可以构造出如下的树(将树结构逆时针选择90度显示): 6 5 4 32很直观地可以理解,输入的String数组是对树结构进行“层序”遍历得到的结果。以下代码用于构造树结构,并提供printTree用于打印树结构。package util;import java.util.LinkedList;import java.util.Queue;public class util { public static class TreeNode { int val;... 阅读全文
posted @ 2013-06-18 22:35 wlu 阅读(2734) 评论(0) 推荐(0) 编辑
摘要: Path Sum IIGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1return[... 阅读全文
posted @ 2013-06-18 20:46 wlu 阅读(244) 评论(0) 推荐(0) 编辑