LeetCode解题思路】的更多相关文章

终于刷完了leetcode的前250道题的easy篇.好吧,其实也就60多道题,但是其中的套路还是值得被记录的. 至于全部code,请移步github,题目大部分采用python3,小部分使用C,如有问题和建议,欢迎指正. String 有一个string库,可以返回各种string的汇总,很值得用. 当题目中需要实现字符串替代的时候,python中有一个自带的translate()函数可以实现这个功能,具体可见Python3字符串替换replace(),translate(),re.sub()…
刷完题后,看一下其他人的solution,受益匪浅. 可以按不同的topic刷题,比如数组.字符串.集合.链表等等.先做十道数组的题,接着再做十道链表的题. 刷题,最主要的是,学习思路. 多刷几遍.挑面试常考的重点刷. 可以采用兔系刷题,就是直接看答案,因为很多算法如果事先不知道是很难靠自己想出来的,知道了思路,刷第二遍的时候就不用看答案了. 龟系刷题,就是自己慢慢磨,花费时间多些,难得也更难忘. 个人习惯用java.当然,练习新的语言时,比如学python时也可以刷题练手. 基础 Char 1…
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOBECODEBANC"T = "ABC" Minimum window is "BANC". Note:If there is no such window i…
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead. For example, given the array [2,3,1,2,4,3] and s = 7,the subarray [4,3] has the minimal…
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens = "leetcode",dict = ["leet", "code"]. Return true because &…
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the longest valid parentheses substring is "()", which has length = 2. Another example is &…
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an e…
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. Your goal is to reach the last index in the minimum number of jumps…
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2…
Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 问题:给定一个单向列表结构,判断它是不是回文的. 补充:是否可以在 O(n) 时间,O(1) 额外空间下完成? 解题思路: 对于数组,判断是否是回文很好办,只需要用两个指针,从两端往中间扫一下就可以判定. 对于单向列表,首先想到的是,将列表复制一份到数组中,然后用上面…