摘要: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and r 阅读全文
posted @ 2017-10-24 11:40 王早 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. 方法一:迭代 方法二:递归 阅读全文
posted @ 2017-10-10 17:32 王早 阅读(92) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: All root-to-leaf paths are: //如果有子节点,字符串随着递归一直累加,直到没 阅读全文
posted @ 2017-09-28 14:27 王早 阅读(94) 评论(0) 推荐(0) 编辑
摘要: Invert a binary tree. to Trivia:This problem was inspired by this original tweet by Max Howell: 方法一:递归 方法二:非递归,栈 阅读全文
posted @ 2017-09-26 11:41 王早 阅读(76) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l 阅读全文
posted @ 2017-09-24 08:42 王早 阅读(68) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet 阅读全文
posted @ 2017-09-23 09:12 王早 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 39、combination sum1 Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the can 阅读全文
posted @ 2017-09-15 17:08 王早 阅读(92) 评论(0) 推荐(0) 编辑
摘要: #include <cstdio>#include <cstring>#include <cmath>#include <map>#include <set>#include <iostream>#include <algorithm>#include <string>using namespace 阅读全文
posted @ 2017-08-09 21:12 王早 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 回溯法的典型 1、Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the giv 阅读全文
posted @ 2017-08-09 10:48 王早 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l 阅读全文
posted @ 2017-08-08 19:04 王早 阅读(96) 评论(0) 推荐(0) 编辑