
Leetcode
小竹子Jobeth
这个作者很懒,什么都没留下…
展开
-
leetcode_two sum
这是leetcode第一道题目,属于easy类型。题目的实例内容是:Given nums = [2,7,11,15], target = 9, Beacause nums[0]+nums[1] = 9 return [0,1]这道题用到的主要算法步骤如下: 1. 将数组按照从小到大的顺序排序 2. 同时从数组num两端开始扫描(序号分别为i,j) 3. 判断num[i]+num[j]是否等于ta原创 2016-09-29 19:19:19 · 344 阅读 · 0 评论 -
leetcode_add two nums
这是leetcode第二题,属于medium难度,题目如下:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two nu原创 2016-10-01 16:07:17 · 289 阅读 · 0 评论 -
leetcode_Longest Substring Without Repeating Characters
这道题是leetcode第三题,leetcode把它分到了medium的难度,题目如下: Given a string, find the length of the longest substring without repeating characters.Examples: Given “abcabcbb”, the answer is “abc”, which the length is原创 2016-10-04 23:16:04 · 303 阅读 · 2 评论 -
leetcode_reverse Integer
leetcode第七题,做了很长世间才想起来没写这个。难度easy。 示例如下: Example1: x = 123, return 321 Example2: x = -123, return -321 题目有个陷阱就是需要考虑到翻转之后越界的问题,因此这个判断是不可避免的。在很多与整数有关的题目中,需要考虑到越界问题,如果跟指针有关,还需要考虑空指针的问题,如果跟字符串有关,则需要考虑到空字符原创 2017-01-26 15:04:24 · 270 阅读 · 0 评论 -
最长回文子串——Manacher算法
1.对于最长回文字串问题,最简洁暴力的方式就是:找到所有的子串,判断是否为回文子串,记录回文子串长度,选最长的。但是这种解法的时间复杂度是O(n3)O(n3)O(n^3)。 2.Manacher算法 对于所有的回文子串,都有同样的性质,那就是对称,长度为奇数的回文子串,以中间字符为对称轴左右对称,长度为偶数的回文子串,对称轴是中间俩字符的空隙。Manacher算法之所以能提高效率,最主要的原因就转载 2017-02-24 18:36:07 · 372 阅读 · 0 评论