Two Sum    21.4%    Medium

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution.

Example:

Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].

UPDATE (2016/2/13):
The return format had been changed to zero-based indices. Please read the above updated description carefully.

给定一个数组,找到数组中的两个值,使其和为n,假定数组中一定存在这样一组解。

常规的思路是两次循环,如果了解哈希表的话,我们可以用哈希表来记录遍历过的节点,找到当前节点和(n-i)节点所在的位置即可。这样可以在O(n)的时间复杂度里面解决这个问题。

Add Two Numbers    22.3%    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 numbers and return it as a linked list.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

大数字的加法,把两个数字都表示成链表的形式。

Longest Substring Without Repeating Characters    21.6%    Medium

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.

由于是字符串,这样的话递归或者多次循环都会导致超时。技巧还是用hash的方法来记录遍历过的字符,另外一个就是如何减少遍历个数。

Median of Two Sorted Arrays    18.2%    Hard

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

从两个已经排序的数组a[m],b[n]中找到中间的数,如果m+n为偶数,则返回中间两个数的平均值,要求时间复杂度log(m+n)

如果写一个时间复杂度是o(m+n)/2 的方法,思路上就简单了,只需要实现即可。既然要求时间复杂度是log(m+n),意味着需要二分法。这道题可以转换成求第k大元素所在的位置,假设第k大元素在a[m]中的index为x,那么b[n]中的索引为k-x,我们通过二分法找x所在的位置,满足 a[x],b[k-x]中较大的一个元素同时小于a[x+1],b[k-x+1]即可。

Longest Palindromic Substring 22.6% Medium

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.

回文可以理解成对称子串,如aaaa,abc,abba,abcba都是回文,由于此题中假设了前提字符串长度不超过1000,那就意味着我们可以使用递归,不会出现堆栈溢出的情况。每一个回文都一定有一个中轴,因此找最长回文就转化为找中轴的问题,如果回文长度为奇数,中轴为1个元素,回文长度为偶数中轴为2个元素。寻找中轴需要一次循环,每一个中轴寻找对称字符串大概小于2n,因此时间复杂度为 n^2.

有人说更牛逼的解法是后缀树,目前还没有找到相关的材料。

上述问题的参考代码:

https://github.com/cuicheng11165/myleetcode/tree/master/leetcode/leetcode

Leetcode 刷题计划的更多相关文章

  1. LeetCode刷题专栏第一篇--思维导图&时间安排

    昨天是元宵节,过完元宵节相当于这个年正式过完了.不知道大家有没有投入继续投入紧张的学习工作中.年前我想开一个Leetcode刷题专栏,于是发了一个投票想了解大家的需求征集意见.投票于2019年2月1日 ...

  2. LeetCode刷题总结-数组篇(上)

    数组是算法中最常用的一种数据结构,也是面试中最常考的考点.在LeetCode题库中,标记为数组类型的习题到目前为止,已累计到了202题.然而,这202道习题并不是每道题只标记为数组一个考点,大部分习题 ...

  3. LeetCode刷题总结-树篇(上)

          引子:刷题的过程可能是枯燥的,但程序员们的日常确不乏趣味.分享一则LeetCode上名为<打家劫舍 |||>题目的评论: 如有兴趣可以从此题为起点,去LeetCode开启刷题之 ...

  4. C#LeetCode刷题-动态规划

    动态规划篇 # 题名 刷题 通过率 难度 5 最长回文子串   22.4% 中等 10 正则表达式匹配   18.8% 困难 32 最长有效括号   23.3% 困难 44 通配符匹配   17.7% ...

  5. leetcode 刷题进展

    最近没发什么博客了 凑个数 我的leetcode刷题进展 https://gitee.com/def/leetcode_practice 个人以为 刷题在透不在多  前200的吃透了 足以应付非算法岗 ...

  6. LeetCode刷题指南(字符串)

    作者:CYC2018 文章链接:https://github.com/CyC2018/CS-Notes/blob/master/docs/notes/Leetcode+%E9%A2%98%E8%A7% ...

  7. Codeforces刷题计划

    Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1 ...

  8. BZOJ第一页刷题计划

    BZOJ第一页刷题计划 已完成:67 / 90 [BZOJ1000]A+B Problem:A+B: [BZOJ1001][BeiJing2006]狼抓兔子:最小割: [BZOJ1002][FJOI2 ...

  9. leetcode刷题记录--js

    leetcode刷题记录 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但 ...

随机推荐

  1. Maven 命令

    win7环境下,Maven跳过测试编译项目的命令: 首先,在cmd环境下执行cd命令移动到需要编译的项目的home目录,然后执行命令:mvn    install -Dmaven.test.skip= ...

  2. winform进程、线程、TreeView递归加载

    进程: 一般来说,一个程序就是一个进程,不过也有一个程序需要多个进程支持的情况. 进程所使用的类:Process 所需命名空间:System.Diagnostics; 可以通过进行来开启计算机上现有的 ...

  3. Puppet自动化运维-资源介绍篇(4)

    1.什么是资源? 资源是Puppet最基础的元素,每个资源的定义都具有标题,类型,以及一系列的属性. 资源定义有如下的特性:   (1) Puppet使用title在编译时区分每个资源,使用命名变量在 ...

  4. Node.js之NPM工具使用

    1.NPM介绍:包管理工具 (1)允许用户从NPM服务器下载别人编写的第三方包到本地石使用 (2)允许用户从NPM服务器下载并安装别人编写的命令行程序到本地使用 (3)允许用户将自己编写的包或命令行程 ...

  5. TPC-H

    http://blog.csdn.net/leixingbang1989/article/details/8766047

  6. Python学习日志(四)

    列表 列表名 = [元素1,元素2,-] 列表和C中的数组有些相似,但列表的功能更加强大,数组的元素要求是同种类型,但列表可以是混合类型. 跟数组一样,通过元素的索引值,我们可以从列表获取单个数据. ...

  7. SQLServer2005如何批量修改架构名 - wuxiaokaixinguo的专栏

    原文地址:http://blog.csdn.net/wuxiaokaixinguo/article/details/8523093 ) BEGIN SET @name='原构架名.' + @name ...

  8. js模拟抛出球运动

    js练手之模拟水平抛球运动 -匀加速运动 -匀减速运动 模拟运动有些基本的思路,当前所在点的坐标,元素的长宽是多少,向右/向下运动x/y增加,向上/向左运动x/y减少,运动的路程是多少,用什么方程进行 ...

  9. Linux添加开机启动命令

    1.vi /etc/rc.d/rc.local 添加要启动的命令 如: service php-fpm start  //这样,开机就自动启动了php扩展 2. crontab -e   //是写定时 ...

  10. [Leetcode] Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...