leetcode
文章平均质量分 57
SmithZz
=.=
展开
-
LeetCode no. 35
35. Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may as原创 2016-04-02 20:24:50 · 307 阅读 · 0 评论 -
Leetcode no. 37
37. Sudoku SolverWrite 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 solu原创 2016-04-03 00:16:50 · 274 阅读 · 0 评论 -
Leetcode no. 279
279. Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 1原创 2016-04-05 18:24:10 · 348 阅读 · 0 评论 -
Leetcode no. 335
335. Self CrossingYou are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2] metres to the south,x[3] met原创 2016-04-05 20:23:21 · 266 阅读 · 0 评论 -
Leetcode no. 283
283. Move ZeroesGiven an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3,原创 2016-04-06 13:52:55 · 360 阅读 · 0 评论 -
Leetcode no. 40
40. Combination Sum IIGiven a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only原创 2016-04-07 17:13:08 · 248 阅读 · 0 评论 -
Leetcode no. 181 (sql)
181. Employees Earning More Than Their Managers# Write your MySQL query statement belowselect E.namefrom Employee E, Employee Hwhere E.ManagerId= H.Id and E.Salary> H.SalaryThe Employee tab原创 2016-04-06 14:45:36 · 727 阅读 · 1 评论 -
Leetcode no. 238
238. Product of Array Except SelfGiven 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 of nums except nums[i]转载 2016-04-07 18:04:32 · 257 阅读 · 0 评论 -
Leetcode no. 26
26. Remove Duplicates from Sorted ArrayGiven 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原创 2016-04-07 21:29:46 · 244 阅读 · 0 评论 -
Leetcode no. 84
84. Largest Rectangle in HistogramGiven n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.原创 2016-04-12 00:10:09 · 228 阅读 · 0 评论 -
Leetcode no. 182
182. Duplicate EmailsWrite a SQL query to find all duplicate emails in a table named Person.+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d.com || 3 | a@b.com原创 2016-04-12 10:34:19 · 424 阅读 · 0 评论 -
Leetcode no. 80
80. Remove Duplicates from Sorted Array IIFollow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your func原创 2016-04-08 10:48:22 · 486 阅读 · 0 评论 -
Leetcode no. 141
141. Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * class Lis原创 2016-04-12 12:14:56 · 240 阅读 · 0 评论 -
Leetcode no. 330
330. Patching ArrayGiven a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some原创 2016-04-12 16:37:45 · 294 阅读 · 0 评论 -
Leetcode no. 39
39. Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be cho原创 2016-04-12 21:37:30 · 277 阅读 · 0 评论 -
Leetcode no. 21
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./** * Def原创 2016-04-26 10:38:49 · 254 阅读 · 0 评论 -
Leetcode no. 16
16. 3Sum Closest Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that原创 2016-04-26 11:38:55 · 289 阅读 · 0 评论 -
Leetcode no. 228
228. Summary RangesGiven 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"].public class Solution {原创 2016-04-09 15:17:44 · 300 阅读 · 0 评论 -
Leetcode no. 313
313. Super Ugly NumberWrite a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For ex原创 2016-04-09 22:49:44 · 305 阅读 · 0 评论 -
Leetcode no. 18
18. 4SumGiven an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of targe原创 2016-04-26 14:45:43 · 303 阅读 · 0 评论 -
Leetcode no. 139
139. Word BreakGiven a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, given转载 2016-04-26 16:28:42 · 272 阅读 · 0 评论 -
Leetcode no.33
33. Search in Rotated Sorted ArraySuppose 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).You are given a target valu原创 2016-04-13 20:01:35 · 214 阅读 · 0 评论 -
Leetcode no. 81
81. Search in Rotated Sorted Array IIFollow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a functi原创 2016-04-13 21:50:39 · 213 阅读 · 0 评论 -
Leetcode no. 201
201. Bitwise AND of Numbers RangeGiven a range [m, n] where 0 For example, given the range [5, 7], you should return 4.public class Solution { public int rangeBitwiseAnd(int m, int n转载 2016-04-10 16:58:40 · 256 阅读 · 0 评论 -
Leetcode no. 51
51. N-QueensThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the原创 2016-04-14 15:48:29 · 239 阅读 · 0 评论 -
Leetcode no. 52
52. N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.public class Solution { int count=0;原创 2016-04-14 16:48:10 · 256 阅读 · 0 评论 -
Leetcode no. 164
164. Maximum GapGiven an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contain原创 2016-04-11 17:16:07 · 310 阅读 · 0 评论 -
Leetcode no. 78
78. Subsets Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplic原创 2016-04-28 17:20:18 · 336 阅读 · 0 评论 -
Leetcode no. 79
79. Word SearchGiven 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 h原创 2016-05-24 23:06:03 · 243 阅读 · 0 评论 -
Leetcode no. 217
217. Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should r原创 2016-05-24 23:29:30 · 217 阅读 · 0 评论 -
Leetcode no. 219
219. Contains Duplicate IIGiven an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference原创 2016-05-24 23:49:37 · 279 阅读 · 0 评论 -
Leetcode no. 169
169. Majority Element Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-em原创 2016-04-17 00:38:28 · 239 阅读 · 0 评论 -
Leetcode no. 220
220. Contains Duplicate IIIGiven an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most原创 2016-05-25 16:39:24 · 747 阅读 · 0 评论 -
Leetcode no. 344
344. Reverse StringWrite a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".public class Solution { public String原创 2016-05-25 17:11:16 · 232 阅读 · 0 评论 -
Leetcode no. 345
345. Reverse Vowels of a StringWrite a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s原创 2016-05-25 20:07:08 · 312 阅读 · 0 评论 -
Leetcode no. 303
303. Range Sum Query - ImmutableGiven 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]sumRa原创 2016-05-25 20:50:11 · 270 阅读 · 0 评论 -
Leetcode no. 53
53. Maximum SubarrayFind 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 con原创 2016-05-26 00:14:19 · 240 阅读 · 0 评论 -
Leetcode no. 257
257. Binary Tree PathsGiven a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:原创 2016-05-26 01:15:03 · 296 阅读 · 0 评论 -
Leetcode no. 69
69. Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.public class Solution { public int mySqrt(int x) { if (x<=0) return 0; if (x>原创 2016-04-18 23:38:11 · 284 阅读 · 0 评论 -
Leetcode no. 110
110. Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two原创 2016-05-26 21:11:38 · 413 阅读 · 0 评论