平时接触树还比较少,写一篇博文来积累一下树的相关知识. 很早之前在数据结构里面学的树的遍历. 前序遍历:根节点->左子树->右子树 中序遍历:左子树->根节点->右子树 后序遍历:左子树->右子树->根节点 例如:求下面树的三种遍历 前序遍历:abdefgc 中序遍历:debgfac 后序遍历:edgfbca 下面来记录一下今天在九度上面做的一道上海交大的机试题: 题目描述: We are all familiar with pre-order, in-order an…
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. 题目给出的意思很简单.就只是单纯的树的遍历而已.意思是计算出所有左叶子节点的值的和. 我采用递归的方式表示我的遍历顺序,其实主要的是要理解题目的意…
1079. Total Sales of Supply A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys products f…
Combination Sum | Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number of times. For example, given candi…