- 博客(86)
- 资源 (1)
- 收藏
- 关注
原创 207. Course Schedule
There are a total ofncourses you have to take, labeled from0ton-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair...
2019-11-11 22:08:29
172
原创 Word Break
Given anon-emptystringsand a dictionarywordDictcontaining a list ofnon-emptywords, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.Note:The ...
2019-04-18 15:57:37
161
原创 Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5...
2019-04-17 21:08:54
210
原创 Unique Binary Search Trees I II
Givenn, how many structurally uniqueBST's(binary search trees) that store values 1 ...n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST's: 1 ...
2019-04-17 19:51:39
164
原创 91. Decode Ways
A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given anon-emptystring containing only digits, determine t...
2019-04-16 16:12:05
125
原创 90. Subsets II
Given a collection of integers that might contain duplicates,nums, return all possible subsets (the power set).Note:The solution set must not contain duplicate subsets.Example:Input: [1,2,2]...
2019-04-13 17:08:07
124
原创 Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gr...
2019-04-13 15:56:09
181
原创 Search in Rotated Sorted Array II
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e.,[0,0,1,2,2,5,6]might become[2,5,6,0,0,1,2]).You are given a target value to search. If found ...
2019-04-10 21:59:18
193
原创 Sort Colors
75.Sort ColorsGiven an array withnobjects colored red, white or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, w...
2019-04-10 20:58:48
114
原创 Remove Duplicates from Sorted Array II
Given a sorted arraynums, remove the duplicatesin-placesuch that duplicates appeared at mosttwiceand return the new length.Do not allocate extra space for another array, you must do this bymod...
2019-04-10 20:50:58
124
原创 Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n...
2019-04-10 18:10:15
162
原创 Search a 2D Matrix
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right. The first integer of each row...
2019-04-08 20:03:21
116
原创 71. Simplify Path
Given anabsolute pathfor a file (Unix-style), simplify it. Or in other words, convert it to thecanonical path.In a UNIX-style file system, a period.refers to the current directory. Furthermore,...
2019-04-08 12:17:37
156
原创 63. Unique Paths II
A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo...
2019-04-01 09:37:10
108
原创 62. Unique Paths
A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo...
2019-03-31 21:28:46
122
原创 60. Permutation Sequence
The set[1,2,3,...,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence forn= 3:"123" "132" "213" "231" "312"...
2019-03-31 16:23:06
140
原创 56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...
2019-03-28 21:39:19
150
原创 Jump Game
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.Determine if yo...
2019-03-24 23:28:44
137
原创 50. Pow(x, n)
Implementpow(x,n), which calculatesxraised to the powern(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, ...
2019-03-23 23:19:44
117
原创 47. Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]解法:和Permutations解法类似,...
2019-03-23 21:43:54
141
原创 Permutations
Given a collection ofdistinctintegers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]解法:利用递归,模拟树的输出情...
2019-03-21 16:58:31
153
原创 43. Multiply Strings
Given two non-negative integersnum1andnum2represented as strings, return the product ofnum1andnum2, also represented as a string.Example 1:Input: num1 = "2", num2 = "3"Output: "6"Exampl...
2019-03-16 18:02:23
101
原创 40. Combination Sum II
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Each number incandidatesmay...
2019-03-14 21:27:34
85
原创 39. Combination Sum
Given asetof candidate numbers (candidates)(without duplicates)and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Thesamerepeat...
2019-03-14 16:16:51
115
原创 Find First and Last Position of Element in Sorted Array
Given an array of integersnumssorted in ascending order, find the starting and ending position of a giventargetvalue.Your algorithm's runtime complexity must be in the order ofO(logn).If the...
2019-03-05 21:55:13
173
原创 33. Search 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]).You are given a target value to search. If found ...
2019-02-28 21:16:36
114
原创 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)).You may assume nums1 and n...
2019-02-27 10:22:57
119
原创 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...
2019-02-26 13:03:05
103
原创 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...
2019-02-25 10:11:58
95
原创 Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list's nodes, only nodes itself may be changed. Example:Given 1->2->3->4, ...
2019-02-21 21:41:18
94
原创 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...
2019-02-21 09:53:19
100
原创 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 giv...
2019-02-20 21:13:51
114
原创 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 ...
2019-02-19 22:07:25
105
原创 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 ...
2019-02-19 20:48:21
98
原创 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example 1:Input: a = 1, b = 2Output: 3Example 2:Input: a = -2, b = 3Output: 1解法:每轮使用异或保留...
2019-02-19 19:42:18
209
原创 Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Output: t...
2019-02-19 17:28:22
106
原创 Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]Output: [...
2019-02-19 10:01:49
101
原创 342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example 1:Input: 16Output: trueExample 2:Input: 5Output: falseFollow up: Could you solve it witho...
2019-02-18 18:10:30
93
原创 Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Input: "hello"Output: "holle"Example 2:Input: "leetcode"Output: "leotcede"Note:The vowel...
2019-02-18 17:53:55
148
原创 Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sum...
2019-02-18 17:29:02
98
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅