上一页 1 2 3 4 5 6 7 8 ··· 23 下一页
摘要: 递归求解,求出已某个箱子为底,返回最高可以放的箱子堆。DP思想优化,对于已经求过的已某个箱子为底的情况,用一个map记录下来,以后直接返回即可。 注意一些clone等一些语言细节。import java.util.ArrayList;import java.util.HashMap;import ... 阅读全文
posted @ 2014-08-24 10:25 jdflyfly 阅读(1051) 评论(0) 推荐(0) 编辑
摘要: 思路:对于可以选择的面值(面值比num都大,当然不可选),一次选择0次~最多选择的次数,然后递归下去,子函数只能从后面的货币开始选。import java.util.ArrayList;import java.util.List;public class Solution { int[] mo... 阅读全文
posted @ 2014-08-23 22:23 jdflyfly 阅读(507) 评论(0) 推荐(0) 编辑
摘要: 还是permutation的算法,字符串也没什么太大的区别。 先排序,然后注意如何去重。import java.util.ArrayList;import java.util.Arrays;public class Solution { public static ArrayList getP... 阅读全文
posted @ 2014-08-23 22:12 jdflyfly 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 在A[0..n-1]中,满足条件 A[i]==i的索引。给定一个有序数组,设法找到其中的magic index。扩展:考虑有重复元素的情况如何处理。public class Solution { public static int magicIndex(int[] array) { ... 阅读全文
posted @ 2014-08-23 21:51 jdflyfly 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 先异或,然后统计1的个数。统计1的个数可以移位一位一位看,高级的算法 n&(n-1)会消去n最低位的1.扩展 n&(n-1)==0代表什么意思:n是2的某次方或者n==0;int bitSwapRequired(int a,int b){ int count=0; for(int c=a... 阅读全文
posted @ 2014-08-23 16:18 jdflyfly 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 思路:依次减去 0.5,0.25,0.125。。。 够减二进制为1,不够减二进制为0。public class Solution { public static String printBinary(double num) { if (num >= 1 || num 0) { ... 阅读全文
posted @ 2014-08-23 15:58 jdflyfly 阅读(443) 评论(0) 推荐(0) 编辑
摘要: 打印二叉树节点数值总和等于某个给定节点的所有路径,路径可以从任意节点开始,任意节点结束。比如,假设和是8,树如下 的路径有 [[5,3],[8],[5,1,2]]。 5 / \ 3 1 /\ /\4 8 2 6思路:遍历所有路径,对于每一个节点,在其路径中向后寻找sum和为targ... 阅读全文
posted @ 2014-08-22 23:09 jdflyfly 阅读(621) 评论(0) 推荐(0) 编辑
摘要: 基本模仿CC150上的思路,递归地在t1中寻找能与t2的根相同的节点,作为开始比较的开始点,然后递归的比较两个树是否相等。boolean containsTree(TreeNode t1, TreeNode t2){ if(t2==null) return true; ... 阅读全文
posted @ 2014-08-22 22:14 jdflyfly 阅读(366) 评论(0) 推荐(0) 编辑
摘要: Related leetcode questions: BST: https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/ BT, node always in the tree. https://le 阅读全文
posted @ 2014-08-21 00:55 jdflyfly 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 5 / \ 2 6 / \ \ 1 4 7 / 3class Node{ Node left; Node right; Node parent; int val;}/**1.如果有右子树,则结果为右子树的最左节点。... 阅读全文
posted @ 2014-08-21 00:28 jdflyfly 阅读(344) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 23 下一页