![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
YouyouPan
这个作者很懒,什么都没留下…
展开
-
Continuous Subarray Sum (LeetCode Algorithm Problem)
本题主要做的是判断一组序列里面是否有这样一组连续的子序列,他们的和正好能够整除k。 我们逐步分析,一个直观的做法是暴力搜索每一个连续的字串,然后把他们相加,看看能否整除k。我们接上述Example1展开,然后我们发现: 包含第一个元素的子序列有【23,2】,【23,2,4】,【23,2,4,6】,【23,2,4,6,7】 包含第二个元素的子序列有【2,4】,【2,原创 2017-07-04 13:17:38 · 169 阅读 · 0 评论 -
Palindrome Number (LeetCode Algorithm Problem)
本题是判断一个整形数是不是回文,条件是空间复杂度为O(1),更直接的说,就是不能把文字转成string之后,套用Palindrome String哪一题的算法去做。 原题链接Determine whether an integer is a palindrome. Do this without extra space.我的想法很简单,先统计这个数总共有多少位,如果仅有一位,那么就直接就是回文了原创 2017-06-11 20:25:43 · 144 阅读 · 0 评论 -
ZigZag Conversion (LeetCode Algorithm Problem)
本题的要求是将一个普通字符串转化成二维图像下的zigzag形式,最后每行输出字符。 原题链接The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for原创 2017-06-05 17:13:28 · 144 阅读 · 0 评论 -
Swap Nodes in Pairs (LeetCode Algorithm Problems)
这道题应该是一道编程语言题,因为要解决的问题是链表的操作。原题链接Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should us原创 2017-05-29 16:06:38 · 134 阅读 · 0 评论 -
3Sum
本题的要求是在一个输入列表里找出所有三个数加起来等于0的组合。Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solut原创 2017-05-07 16:59:46 · 189 阅读 · 0 评论 -
Letter Combinations of a Phone Number
手机电话按键这道题挺有意思的,题目要求就是将数字组合转换成在能够在手机按键上生成的字符组合。这在电视剧《越狱》中有一个桥段就是通过分析手机的字符组合来知道主角的行踪。而在九宫格输入法里面,这样的组合算法也很常用。这里写链接内容Given a digit string, return all possible letter combinations that the number could repr原创 2017-05-07 16:33:29 · 170 阅读 · 0 评论 -
Container With Most Water
这是一道应用题,题目讲的是,在x轴上,每一个整数点都有一条竖线,竖线的长度由一个数组height描述。那么选择两条竖线,他们和x轴共同形成一个容器(类似一个烧杯)来装水,找到能够装最多水的两条竖线。Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n ve原创 2017-04-24 11:37:13 · 117 阅读 · 0 评论 -
Generate Parentheses(LeetCode Algorithm Problem)
本体是一个括号匹配的问题,但不是检查一串括号是否匹配,而是输入括号的数量,将所有匹配的括号串输出。 原题链接Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is原创 2017-05-12 13:31:02 · 138 阅读 · 0 评论 -
Reverse Words in a String (LeetCode medium algorithm problem)
本题的要求是将一段英文句子中的单词进行倒置。 本题链接Given an input string, reverse the string word by word.For example, Given s = “the sky is blue”, return “blue is sky the”.注意到本题的细节是将单词进行置换,而不是单纯将字符进行倒置。 做法其实并不难,就是找到单原创 2017-04-16 21:13:54 · 139 阅读 · 0 评论 -
Longest Substring Without Repeating Characters(Leetcode medium algorithm problem)
这周刷的题目是Longest Substring Without Repeating Characters,顾名思义,就是找字符串中最长的无重复字母的字串。原题链接Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the an原创 2017-03-27 15:20:32 · 147 阅读 · 0 评论 -
Merge k Sorted Lists (LeetCode hard algorithm problem)
本次的算法题目是Merge k Sorted Lists。 原题链接Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目要求是把k个已经排好序的链表重新组合成一个新的有序链表。 解题想法依然是先尝试最简单粗暴的方法,如果有问题,再在其基础上做出修原创 2017-03-19 17:12:19 · 227 阅读 · 0 评论 -
Regular Expression Matching (Leetcode hard algorithm problem)
经过上周的medium热身之后,这周决定选个hard的来训练一下。 这次题目为正则表达式,描述如下。原题链接‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string (not partia原创 2017-03-05 22:35:38 · 163 阅读 · 0 评论