Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
简单的思想:正序排列时,某节点的右节点一定是该节点的右子树,中序排列,某节点的左节点一定是该节点的左子树;
...
分类:
其他好文 时间:
2014-12-04 18:03:12
阅读次数:
143
题目链接:点击打开链接
题意 :有5种硬币的面值,分别为 1 ,5 ,10 ,25 ,50 。。 给出n 问用这些面值的硬币有多少种组成n的方式。(每种硬币无限,使用硬币数也无限)
两种做法,母函数比较长,以前也写过就不说了。。
第二种做法是DP 设 dp[i] 为组成i 的种类数,初始化dp[0]=1; (有图有真相 题目中原话 :Note that we count that there...
分类:
其他好文 时间:
2014-12-04 15:43:17
阅读次数:
174
# 题目 > Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You...
分类:
其他好文 时间:
2014-12-04 12:23:54
阅读次数:
161
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must be in...
分类:
其他好文 时间:
2014-12-04 12:08:48
阅读次数:
125
判断一个字符串是不是回文,忽略其中的非数字和非字母,例如符号和空格不考虑。For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"isnota palindrome.Note:Have you consider ...
分类:
其他好文 时间:
2014-12-04 00:53:19
阅读次数:
227
Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen...
分类:
其他好文 时间:
2014-12-04 00:38:06
阅读次数:
215
HLSL的基本语法
1 数据类型
1.1 标量类型
1. bool: True or false .Note that the HLSL provides the true and false keywordslike in C++.
2. int: 32-bit signedinteger.
3. half: 16-bit-floatingpoint number.
4. flo...
分类:
其他好文 时间:
2014-12-03 23:26:12
阅读次数:
1711
Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order....
分类:
其他好文 时间:
2014-12-03 22:47:54
阅读次数:
153
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
这类问题非常适合用递归做,递归思路如下:
前序遍历的第一个节点必然是根节点,中序遍历中根节点之前的节...
分类:
其他好文 时间:
2014-12-03 21:27:24
阅读次数:
172
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ...
分类:
其他好文 时间:
2014-12-03 21:14:01
阅读次数:
198