![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
Stephen_R
You are waiting for a train, a train that will take you far away.
展开
-
[LeetCode]38. Count and Say
DescriptionThe count-and-say sequence is the sequence of integers with the first five terms as following: 1 11 21 1211 111221 1 is read off as “one 1” or 11. 11 is read off as “two 1s”原创 2017-10-18 21:53:37 · 246 阅读 · 0 评论 -
[LeetCode]19. Remove Nth Node From End of List
DescriptionGiven a linked list, remove the nth node from the end of list and return its head.Example Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the l原创 2017-10-07 21:06:46 · 113 阅读 · 0 评论 -
[LeetCode]20. Valid Parentheses
DescriptionGiven a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all原创 2017-10-07 22:02:01 · 209 阅读 · 0 评论 -
[LeetCode]22. Generate Parentheses
DescriptionGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.ExampleFor example, given n = 3, a solution set is: [ “((()))”, “(()())”,原创 2017-10-08 14:11:44 · 110 阅读 · 0 评论 -
[LeetCode]26. Remove Duplicates from Sorted Array
DescriptionGiven a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in plac原创 2017-10-14 13:38:36 · 168 阅读 · 0 评论 -
[LeetCode]28. Implement strStr()
DescriptionImplement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Discussion判断needle是否是haystack的子串,并返回子串的起始位置。暴力破解法。每次判断haystack串的i~原创 2017-10-14 14:50:27 · 132 阅读 · 0 评论 -
[LeetCode]29. Divide Two Integers
DescriptionDivide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Discussion不用乘除和模运算来算整数除法。最简单而直观的方法就是用被除数一直减除数,直到为0。另外,我们可以采用左移右移来提高效率。我们知道任何一个整数原创 2017-10-14 15:59:37 · 111 阅读 · 0 评论 -
[LeetCode]36. Valid Sudoku
DescriptionDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.A partially filled su原创 2017-10-23 19:39:52 · 153 阅读 · 0 评论 -
[LeetCode]37. Sudoku Solver
DescriptionWrite a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character ‘.’.You may assume that there will be only one unique solution.A sudoku puzzle…原创 2017-10-23 23:44:16 · 165 阅读 · 0 评论 -
[LeetCode]33. Search in Rotated Sorted Array
DescriptionSuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If foun原创 2017-10-15 17:30:45 · 124 阅读 · 0 评论 -
[LeetCode]41. First Missing Positive
DescriptionGiven an unsorted integer array, find the first missing positive integer.Your algorithm should run in O(n) time and uses constant space.Example Given [1,2,0] return 3, and [3,4,-1,1] re原创 2017-11-01 16:21:48 · 129 阅读 · 0 评论 -
[LeetCode]17. Letter Combinations of a Phone Number
DescriptionGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Example Inpu原创 2017-10-06 15:57:36 · 147 阅读 · 0 评论 -
[LeetCode]21. Merge Two Sorted Lists
DescriptionMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Disgussion合并排序问题的最后一步。算法的时间复杂度为O(n)。C++ Code/**原创 2017-09-30 10:58:37 · 112 阅读 · 0 评论 -
[LeetCode]15. 3Sum
DescriptionGiven 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 solution set must not con原创 2017-09-30 10:51:33 · 111 阅读 · 0 评论 -
[LeetCode]34. Search for a Range
DescriptionGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If th原创 2017-10-19 19:37:20 · 145 阅读 · 0 评论 -
[LeetCode]1. Two Sum
DescriptionGiven 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, and you may not use t原创 2017-09-29 10:55:09 · 186 阅读 · 1 评论 -
[LeetCode]2. Add Two Numbers
DescriptionYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers an原创 2017-09-29 14:49:05 · 134 阅读 · 0 评论 -
[LeetCode]4. Median of Two Sorted Arrays
DescriptionThere 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)).Example Example 1原创 2017-09-29 18:26:09 · 107 阅读 · 0 评论 -
[LeetCode]5. Longest Palindromic Substring
DescriptionGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example Input: “babad” Output: “bab” Note: “aba” is also a valid an原创 2017-09-29 18:51:00 · 109 阅读 · 0 评论 -
[LeetCode]7. Reverse Integer
DescriptionReverse digits of an integer.The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.Example Example1: x = 123, return 321原创 2017-09-29 19:39:30 · 108 阅读 · 0 评论 -
[LeetCode]8. String to Integer(atoi)
DescriptionImplement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible in原创 2017-09-29 19:44:46 · 100 阅读 · 0 评论 -
[LeetCode]10. Regular Expression Matching
DescriptionImplement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire i原创 2017-09-29 20:03:50 · 166 阅读 · 0 评论 -
[LeetCode]11. Container With Most Water
DescriptionGiven n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). F原创 2017-09-29 20:16:12 · 104 阅读 · 0 评论 -
[LeetCode]13. Roman to Integer
DescriptionGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Disgussion罗马数字转成阿拉伯数字。我们需要知道罗马数字的构成规则。罗马数字通过7个不同字母的重复或组合,能够表示出1到3999的所有数字。 I V原创 2017-09-29 20:33:34 · 120 阅读 · 0 评论 -
[LeetCode]14. Longest Common Prefix
DescriptionWrite a function to find the longest common prefix string amongst an array of strings.Disgussion查找公共前缀的问题。只需要从头开始把每个数组的第i个字符进行比较,有不一样的就跳出循环即可。另外需要注意特殊情况处理。算法的时间复杂度为O(n)。C++ Codeclass Solutio原创 2017-09-30 10:36:50 · 119 阅读 · 0 评论 -
[LeetCode]23. Merge k Sorted Lists
DescriptionMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Disgussion合并k个有序的链表。最直观的方法自然先合并前两个1和2,再合并12和3,再合并123和4……但是这样的话效率并不高。因为每次要比较的链表长度呈直线上升。更好的方法是原创 2017-10-09 17:38:46 · 155 阅读 · 0 评论