- 博客(35)
- 收藏
- 关注
原创 【LeetCode】94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]Follow up: Recursive solution is trivial, could y...
2018-08-30 10:47:11
152
原创 【LeetCode】32. Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid...
2018-08-21 11:56:29
226
原创 【LeetCode】31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o...
2018-08-12 06:40:22
191
原创 【LeetCode】30. Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wi...
2018-08-11 04:33:37
281
原创 【LeetCode】29. Divide Two Integers
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division sho...
2018-08-11 03:14:16
165
原创 【LeetCode】28. Implement strStr()
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example...
2018-08-10 11:41:13
153
原创 【LeetCode】27. Remove Element
Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input arra...
2018-08-10 10:44:24
134
原创 【LeetCode】26. Remove Duplicates from Sorted Array
Given a sorted array nums, 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 by modifyi...
2018-08-10 10:30:57
142
原创 【LeetCode】25. Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of ...
2018-08-07 13:38:42
165
原创 【LeetCode】24. Swap Nodes in Pairs
Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only constant extra space. You may not modify the values in the list's nodes...
2018-08-07 11:41:25
134
原创 【LeetCode】23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4-...
2018-07-22 06:38:30
185
原创 【LeetCode】22. Generate Parentheses
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:[ "((()))", "(()())", "(())()", "()(())", "...
2018-07-16 11:48:41
302
原创 【LeetCode】21. Merge Two Sorted Lists
Merge 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.Example:Input: 1->2->4, 1->3->4Output: 1->1...
2018-07-15 00:32:59
189
原创 【LeetCode】20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brack...
2018-07-15 00:02:18
184
原创 【LeetCode】19. Remove Nth Node From End of List
Given a linked list, remove the n-th 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 li...
2018-06-26 12:09:22
212
原创 【LeetCode】18. 4Sum
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of tar...
2018-06-25 12:55:38
142
原创 【LeetCode】17. Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given...
2018-06-25 06:45:44
234
原创 【LeetCode】16. 3Sum Closest
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...
2018-06-20 10:42:01
162
原创 【LeetCode】15. 3Sum
Given an array nums of n integers, are there elements a, b, c in nums 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 contain ...
2018-06-20 09:53:29
135
原创 【LeetCode】14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["flower","flow","flight"]Output: "fl"E...
2018-06-12 11:38:18
133
原创 【LeetCode】13. Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 5...
2018-06-11 06:31:03
166
原创 【LeetCode】12. Integer to Roman
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 5...
2018-05-22 12:14:07
164
原创 【LeetCode】11. Container With Most Water
Given 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). Find two ...
2018-05-21 12:59:39
125
原创 【LeetCode】10. Regular Expression Matching
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The...
2018-05-15 12:09:03
188
原创 【LeetCode】8. String to Integer (atoi)
Implement 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 input cases....
2018-04-10 03:09:06
173
原创 【LeetCode】9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.思路:edge case:x < 0 ==> falsex == 0 ==> truex = 10, 100,... ==> false解法一:1. 如果input x是负数,直接返回false2. 考虑overflow情况,因...
2018-03-26 12:59:41
139
原创 【LeetCode】7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with an envi...
2018-03-26 11:26:57
139
原创 【LeetCode】6. ZigZag Conversion
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 better legibility)P A H NA P L S I I G...
2018-03-26 10:16:33
121
原创 【LeetCode】5. Longest Palindromic Substring
Given 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 answer. Example:I...
2018-03-26 06:19:02
145
原创 【Leetcode】4. Median of Two Sorted Arrays
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)).Example 1:nums1 = [1, 3]nums2...
2018-03-25 11:55:36
139
原创 【Leetcode】3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the l...
2018-03-22 09:50:58
140
原创 【Leetcode】2. Add Two Numbers
You 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 and return i...
2018-03-22 08:36:45
196
原创 【LeetCode】Search a 2D Matrix 解题报告
【题目】Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer
2018-01-30 13:24:19
160
原创 【LeetCode】Find Minimum in Rotated Sorted Array 解题报告
【题目】Suppose 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).Find the minimum element.You may
2018-01-29 12:12:46
159
原创 【LeetCode】First Bad Version 解题报告
【题目】You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed ba
2018-01-29 07:37:20
189
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人