摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
先来解决二叉树节点间的最大距离问题。 最大距离来自以下几种可能:1. 左子树的最大距离lmax; 2. 右子树的最大距离rmax; 3. 左子树距根节点的最大距离maxFromLeft + 右子树距根节点的最大距离maxFromRight + 1; 于是,得出以下步骤: ①. 后续遍历整棵树, 对每 阅读全文
摘要:
之前看到这个问题,没有头绪,参考了http://www.tuicool.com/articles/NZBNZ3Z的解法,里面循环的问题稍微理清了一下。 废话不说,先上题。 有n个气球,编号为0到n-1,每个气球都有一个分数,存在nums数组中。每次吹气球i可以得到的分数为 nums[left] * 阅读全文
摘要:
T2: 数组排成最小数(在Collections.sort中传入比较器) 阅读全文
摘要:
用暴力递归的话,以图中的测试用例为例,先让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 号员工选择 阅读全文
摘要:
递归时间复杂度过高,故用迭代来做。 生成两个int变量backOne backTwo, 记录已经计算过的f(n)值。 阅读全文