Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexi ...
分类:
其他好文 时间:
2016-10-21 08:00:01
阅读次数:
202
最长公共子序列是经典的动态规划问题,在很多书籍和文章中都有介绍,这里对这一经典算法进行回顾并对两个follow up questions进行总结和分析。 1. 回顾LCS(longest common subsequence)解法,求LCS长度 典型的双序列动态规划问题,dp[i][j]表示第一个序 ...
分类:
其他好文 时间:
2016-10-21 00:28:03
阅读次数:
266
题意: 给定非排序数组,找出其排序后相邻元素的最大差值。 线性时间空间、元素数少于2时返回0、元素值非负且int范围内。 思路: 排序最快nlogn不符合要求; 参考网上,学习了桶排序的方法; 桶排序:按值分段处理; 设定桶大小和桶个数; 因为ans>=(MAX-MIN)/(len-1); 桶大小: ...
分类:
其他好文 时间:
2016-10-21 00:18:09
阅读次数:
116
有关概念: 最长公共子序列(LCS,Longest Common Subsequence),两个或者两个以上的所有共同子序列最长的一个(好像和没解释没什么区别) 思路: 对于两个序列a,b f[i][j]表示a序列中1..i的部分和b序列中1...j的部分的LCS 那么易得,对于f[i][j]: ( ...
分类:
其他好文 时间:
2016-10-20 07:26:20
阅读次数:
133
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the knumb ...
html5移动开发细微之美 1、H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user ...
分类:
移动开发 时间:
2016-10-18 15:50:18
阅读次数:
216
有关概念: 最长上升子序列(LIS,Longest Increasing Subsequence),在一个序列中最长的单调递增的子序列 思路: 求LIS通常有O(n2)和O(nlogn)两种算法 (1)O(n2)算法 fi表示以第i个数结尾的LIS长度 对于序列中的一个数i,在i前面枚举数j,j满足 ...
分类:
其他好文 时间:
2016-10-18 01:49:15
阅读次数:
118
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-s ...
分类:
其他好文 时间:
2016-10-16 23:38:24
阅读次数:
284
https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/ 利用了异或的”自反性“: a ^ b = c,而a ^ b ^ b = a, 则 c ^ b = a 其他运算定律有:交换律、结合律、分配律。 ...
分类:
其他好文 时间:
2016-10-16 13:54:22
阅读次数:
128
最长公共子序列问题 核心代码: UVA10405 Longest Common Subsequence 模板题 代码: UVA10252 Common Permutation 求一个最长子序列。使得子序列的全排列中有一个(可以不相同)是2个字符串的子序列. 仔细思考并不是LCS问题,直接模拟有多少个 ...
分类:
其他好文 时间:
2016-10-15 22:39:44
阅读次数:
226