摘要: 背包问题: 在n个物品中挑选若干物品装入背包,最多能装多满?假设背包的大小为m,每个物品的大小为A[i] 注意事项: 你不可以将物品进行切割。 样例: 你不可以将物品进行切割。 样例: 你不可以将物品进行切割。 样例: 如果有4个物品[2, 3, 5, 7] 如果背包的大小为11,可以选择[2, 3 阅读全文
posted @ 2017-09-21 17:05 Revenent 阅读(384) 评论(0) 推荐(0) 编辑
摘要: 题目内容: We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you gues 阅读全文
posted @ 2017-09-21 15:47 Revenent 阅读(425) 评论(0) 推荐(0) 编辑
摘要: 不同的二叉查找树I: 题目内容: 给出 n,问由 1...n 为节点组成的不同的二叉查找树有多少种? 样例: 给出n = 3,有5种不同形态的二叉查找树: 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3 算法分析: 先来看一下二叉查找树的特点,当选 阅读全文
posted @ 2017-09-21 14:55 Revenent 阅读(664) 评论(0) 推荐(0) 编辑
摘要: 题目内容: Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 阅读全文
posted @ 2017-09-20 12:40 Revenent 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 题目内容: Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements i 阅读全文
posted @ 2017-09-18 21:12 Revenent 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 427-生成括号 题目:给定 n 对括号,请写一个函数以将其生成新的括号组合,并返回所有组合结果。 样例:给定 n = 3, 可生成的组合如下:"((()))", "(()())", "(())()", "()(())", "()()()" 算法:对于给定的n,定义一个result字符串,当字符串中 阅读全文
posted @ 2017-09-15 23:23 Revenent 阅读(335) 评论(0) 推荐(0) 编辑
摘要: 在做LintCode上的递归类题目子集时,我一开始的想法是递归到最后一层即单元素时然后开始逐层返回,产生相应的每层的子集并添加到最终的结果中去。于是乎有了以下代码: 算法似乎很正确,每层返回处理的时候有一个pre_result和result两个List,其中result由new ArrayList< 阅读全文
posted @ 2017-08-31 14:45 Revenent 阅读(147) 评论(0) 推荐(0) 编辑
摘要: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font 阅读全文
posted @ 2017-08-15 11:05 Revenent 阅读(303) 评论(0) 推荐(0) 编辑