- 博客(28)
- 收藏
- 关注
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [读书]大雪中的山庄——东野圭吾
《大雪中的山庄》这本书最开始读的时候感觉不就是《无人生还》的翻版嘛,你还能玩出什么花样。读完之后才发现东野圭吾构建的三重构造戏中戏中戏,真的是精彩,不落俗套。第一重戏:东乡导演要求7位演员在大雪中的山庄中排演。 第二重戏:麻仓小姐拟定了二重构造复仇计划。第三重戏:本多与笠原,元村和雨宫合谋上演假复仇给麻仓看。身处残酷的处境时,人就会抢着说消极绝望的话,内心却期待着被人否定。
2017-10-10 22:08:46
2632
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
原创 [LeetCode]3. Longest Substring Without Repeating Characters
DescriptionGiven a string, find the length of the longest substring without repeating characters.Example Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer i
2017-09-29 15:25:01
101
原创 [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
原创 [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
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人