摘要: 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 = 0 or  阅读全文
posted @ 2017-05-18 22:51 贾斯彼迭 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from t 阅读全文
posted @ 2017-05-16 23:24 贾斯彼迭 阅读(497) 评论(0) 推荐(0) 编辑
摘要: A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1 Given an encoded message containing digits, det 阅读全文
posted @ 2017-05-15 23:46 贾斯彼迭 阅读(671) 评论(0) 推荐(0) 编辑
摘要: 先来解决二叉树节点间的最大距离问题。 最大距离来自以下几种可能:1. 左子树的最大距离lmax; 2. 右子树的最大距离rmax; 3. 左子树距根节点的最大距离maxFromLeft + 右子树距根节点的最大距离maxFromRight + 1; 于是,得出以下步骤: ①. 后续遍历整棵树, 对每 阅读全文
posted @ 2017-05-15 14:49 贾斯彼迭 阅读(1650) 评论(0) 推荐(0) 编辑
摘要: 之前看到这个问题,没有头绪,参考了http://www.tuicool.com/articles/NZBNZ3Z的解法,里面循环的问题稍微理清了一下。 废话不说,先上题。 有n个气球,编号为0到n-1,每个气球都有一个分数,存在nums数组中。每次吹气球i可以得到的分数为 nums[left] * 阅读全文
posted @ 2017-05-15 10:33 贾斯彼迭 阅读(547) 评论(0) 推荐(0) 编辑
摘要: T2: 数组排成最小数(在Collections.sort中传入比较器) 阅读全文
posted @ 2017-04-16 15:36 贾斯彼迭 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 用暴力递归的话,以图中的测试用例为例,先让A号选择0号活,在让2-n 号员工选择1-5号活 有res1种 让A号选择1号活,在让2-n 号员工选择0, 2-5号活 有res2种 让A号选择2号活,在让2-n 号员工选择0-1,3-5号活 有res3种 。。。 让A号选择5号活,在让2-n 号员工选择 阅读全文
posted @ 2017-03-30 22:24 贾斯彼迭 阅读(330) 评论(0) 推荐(0) 编辑
摘要: 递归时间复杂度过高,故用迭代来做。 生成两个int变量backOne backTwo, 记录已经计算过的f(n)值。 阅读全文
posted @ 2017-03-20 21:59 贾斯彼迭 阅读(1590) 评论(0) 推荐(0) 编辑
摘要: 一、全部逆序 定义两个变量pre, next,与节点head一起,遍历整个链表。 二、 部分逆序 首先找到需要逆序的节点区域的前一个节点和后一个节点。记为 pre,pos。 定义3个变量cur, next1, next2. 遍历链表。 阅读全文
posted @ 2017-03-12 22:24 贾斯彼迭 阅读(567) 评论(0) 推荐(0) 编辑
摘要: 一. 快速排序的划分 要求:数组划分分左右两部分,左边比pivot小,右边比pivot大 实现过程:1. 定义变量left,right,分别表示未整理的子数组最左和最右的下标。 2、定义游标leftPtr,遍历left部分,初始值为left-1;定义游标rightPtr,遍历right部分,初始值为 阅读全文
posted @ 2017-03-12 10:24 贾斯彼迭 阅读(179) 评论(0) 推荐(0) 编辑