- 博客(169)
- 收藏
- 关注
原创 [Leetcode]57. Insert Interval
iven a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Ex
2016-09-07 17:21:33
648
原创 [Leetcode]94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recursive solu
2016-08-21 21:02:27
510
原创 [Leetcode]103. Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary
2016-08-16 21:57:09
485
原创 [Leetcode]10. Regular Expression Matching
Implement 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 input st
2016-08-15 21:56:36
703
原创 [Leetcode]151. Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".class Solution {public: void reverseWords(string &s) {
2016-08-13 11:37:41
386
原创 [Leetcode]264. Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first
2016-07-28 18:42:58
350
原创 [Leetcode]53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1]
2016-07-27 23:00:22
288
原创 [Leetcode]138. Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.解法1:/** * Definition for
2016-07-26 17:42:46
337
原创 [Leetcode]54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]
2016-07-25 11:17:18
508
原创 [Leetcode]74. 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 of each
2016-07-24 15:31:24
276
原创 [Leetcode]105. Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for a binary tree node. * struct Tre
2016-07-24 15:26:03
286
原创 [Leetcode]152. Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges
2016-07-21 20:04:25
270
原创 [Leetcod]154. Find Minimum in Rotated Sorted Array II
Suppose a sorted array 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.The array may contain duplicates.c
2016-07-21 19:35:32
218
原创 [Leetcode]153. Find Minimum in Rotated Sorted Array
Suppose a sorted array 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 assume no duplicate exists in
2016-07-21 19:12:11
233
原创 [Leetcode]162. Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in
2016-07-21 17:29:09
392
原创 [Leetcode]209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3
2016-07-20 21:47:28
265
原创 [Leetcode]216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Example 1:Inpu
2016-07-20 18:59:25
297
原创 [Leetcode]228. Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].class Solution {public: vector summaryRanges(v
2016-07-20 16:41:05
346
原创 [leetcode]229. Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.Hint:How many majority elements could it
2016-07-20 16:00:00
295
原创 [Leetcode]238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division and in O(
2016-07-20 08:24:06
248
原创 [Leetcode]268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm sho
2016-07-19 22:05:57
252
原创 [Leetcode]287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,
2016-07-19 21:52:27
232
原创 [Leetcode]289. Game of Life
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m
2016-07-19 20:15:04
255
原创 [Leetcode]368. Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple solution
2016-07-18 15:45:21
246
原创 [Leetcode]322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money
2016-07-18 12:23:37
242
原创 [Leetcode]Guess Number Higher or Lower II
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number I pi
2016-07-18 10:19:19
535
原创 [Leetcode]165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2016-07-17 20:35:17
228
原创 [Leetcode]189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].class Solution {public: void rotate(vect
2016-07-17 17:07:36
439
原创 [Leetcode]278. 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 based on the
2016-07-17 16:13:00
253
原创 [Leetcode]7. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c
2016-07-16 19:06:05
211
原创 [Leetcode]125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a
2016-07-16 17:32:56
233
原创 [Leetcode]204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.class Solution {public: int countPrimes(int n) { bool isPrime[n]; for (int i = 2; i < n; +
2016-07-16 17:06:46
197
原创 [Leetcode]303. 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) -> -1sumRan
2016-07-15 19:25:40
201
原创 [Leetcode]28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.class Solution {public: int strStr(string haystack, string need
2016-07-15 18:18:34
208
原创 [Leetcode]67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".class Solution {public: string addBinary(string a, string b) { stri
2016-07-15 17:11:11
197
原创 [Leetcode]14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector& strs) { if (strs.empty()) re
2016-07-15 16:34:15
179
原创 [Leetcode]190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010
2016-07-15 15:28:39
280
原创 [Leetcode]58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is
2016-07-14 22:12:05
239
原创 [Leetcode]374. Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is h
2016-07-14 21:45:56
276
原创 [Leetcode]38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as
2016-07-14 21:18:58
166
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人