05 2017 档案
摘要:给定一个数组,玩家A,B每次从数组头或尾取数,且只能从头尾取。假定A,B都绝顶聪明,均采取最优策略,判断A先手的情况下,A是否能够获胜。 分析: f(i, j) 表示 在arr[i~j]中A 先手时能够获得的最大分数,s(i, j) 表示 A后手时能够获得的最大分数。 首先分析f(i, j)。 A可
阅读全文
摘要: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] *
阅读全文

浙公网安备 33010602011771号