- 博客(18)
- 资源 (5)
- 收藏
- 关注
原创 递归 循环 比较
算法分析: 循环算法和递归算法 无论时间效率还是空间效率都是前者高。递归算法在运行时,函数调用保存现场、开辟运行资源、返回回收资源都需要耗时。递归算法的参数表面是一个变量,实际上市一个栈。结论1:递归确实是一些复杂的问题处理起来简单明了,但是,就效率而言,递归算法的实现往往比循环算法耗费更多的时间和存储空间,也限制了递归的深度。所以,在具体的实现中,应尽可能把递归算法转换为等价
2014-06-05 09:41:18 1522
原创 leetcode Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2014-05-12 09:46:35 505
原创 leetcode Longest Valid Parentheses
思路://引入一个bool数组flag[], flag[i]标记i位置能不能匹配 //最后统计最长true的长度class Solution {public: //引入一个bool数组flag[], flag[i]标记i位置能不能匹配 //最后统计最长true的长度 int longestValidParentheses(string s) {
2014-05-08 16:46:16 472
转载 leetcode First Missing Positive
思路:虽然不能再另外开辟非常数级的额外空间,但是可以在输入数组上就地进行swap操作。思路:交换数组元素,使得数组中第i位存放数值(i+1)。最后遍历数组,寻找第一个不符合此要求的元素,返回其下标。整个过程需要遍历两次数组,复杂度为O(n)。下图以题目中给出的第二个例子为例,讲解操作过程。int firstMissingPosit
2014-05-08 11:07:20 496
原创 leetcode Palindrome Partitioning II
题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab"
2014-05-08 10:21:39 564
原创 hadoop 安装 配置 平台搭建
本平台是基于vmware+Ubuntu的,所以平台搭建基础是vmare上面安装ubuntu系统。系统安装就不在说了。NOTE:每个ubuntu上的用户名必须一致。下面我的用户名为zgw。
2014-05-07 20:25:19 569
原创 leetcode Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","
2014-05-07 17:06:48 490
原创 leetcode Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu
2014-05-07 14:05:53 464
原创 leetcode Restore IP Addresses
题目 :Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Or
2014-05-06 17:02:46 494
原创 leetcode Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:
2014-05-06 15:23:08 447
原创 leetcode Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i
2014-05-05 20:04:23 537
转载 leetcode Max Points on a Line
文章摘自:http://blog.csdn.net/doc_sgl/article/details/17103427分析:任意一条直线都可以表述为y = ax + b假设,有两个点(x1,y1), (x2,y2),如果他们都在这条直线上则有y1 = kx1 +by2 = kx2 +b由此可以得到关系,k = (y2-y1)/(x2
2014-05-04 19:54:37 446
原创 leetcode Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.
2014-05-04 16:03:37 596
原创 leetcode Best Time to Buy and Sell Stock II
分析:题目的意思是整个过程中只能买一只股票然后卖出,也可以不买股票。也就是我们要找到一对最低价和最高价,最低价在最高价前面,以最低价买入股票,以最低价卖出股票。可以买卖多次股票,但是不能连续买股票,也就是说手上最多只能有一只股票(注意:可以在同一天卖出手上的股票然后再买进)
2014-05-04 15:13:15 770
原创 leetcode Best Time to Buy and Sell Stock
题目的意思是整个过程中只能买一只股票然后卖出,也可以不买股票。也就是我们要找到一对最低价和最高价,最低价在最高价前面,以最低价买入股票,以最低价卖出股piao
2014-05-04 14:39:54 612
原创 elasticsearch ik 分词
一、如果只需要将"维基百科"单独分开,只需要做如下处理, 1、确定词典中有“维基”、“百科”这两个词,并且没有“维基百科”这个词 2、ik分词采用智能分词模式,也就是这个ik_smart二、如果需要将"维基百科"分成三个词"维基百科","维基","百科",那么需要做如下处理 1、确保词典中有“维基”、“百科”、"维基百
2014-04-30 14:45:09 823
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人