
leetcode
文章平均质量分 70
xuyueqing1225
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
(java)leetcode-89:Gray Code
Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the s原创 2017-08-30 21:04:36 · 306 阅读 · 0 评论 -
(java)leetcode-70:Climbing Stairs
Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n原创 2017-07-23 20:02:09 · 243 阅读 · 0 评论 -
(java)leetcode-69:Sqrt(x)
Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.解题思路:这道题我的思路就是二分法查找结果了,这个比较简单就不多说。public class Solution { public int mySqrt(int x) { long longx = x原创 2017-07-23 19:42:42 · 307 阅读 · 0 评论 -
(java)leetcode-68:Text Justification
Text JustificationGiven an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a g原创 2017-07-23 19:04:12 · 332 阅读 · 0 评论 -
(java)leetcode-67:Add Binary
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".解题思路:这道题就是两个二进制数相加,记得加上进位的值就好了。public class Solution {原创 2017-07-23 11:34:51 · 243 阅读 · 0 评论 -
(java)leetcode-66:Plus One
Plus OneGiven a non-negative integer represented as anon-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.原创 2017-07-23 10:52:37 · 259 阅读 · 0 评论 -
(java)leetcode-64:Minimum Path Sum
Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move eithe原创 2017-07-23 10:29:24 · 208 阅读 · 0 评论 -
(java)leetcode-63:Unique Paths II
Unique Paths IIFollow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respe原创 2017-07-20 22:14:19 · 202 阅读 · 0 评论 -
(java)leetcode-62:Unique Paths
Unique PathsA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying原创 2017-07-20 21:51:25 · 186 阅读 · 0 评论 -
(java)leetcode-61:Rotate List
Rotate ListGiven a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.解题思路:这个题我觉得要分成两种原创 2017-07-20 21:15:14 · 196 阅读 · 0 评论 -
(java)leetcode-9
Palindrome NumberDetermine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the in转载 2017-04-13 12:25:50 · 160 阅读 · 0 评论 -
(java)leetcode-49
Group AnagramsGiven an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]原创 2017-07-05 22:31:33 · 211 阅读 · 0 评论 -
(java)leetcode-48
Rotate Image You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?解题思路:题意要求说用原有的空间。所以主要是搞懂那个旋转的顺序就好了原创 2017-07-05 22:08:33 · 268 阅读 · 0 评论 -
(java)leetcode-1
Reverse IntegerReverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Note:The input is assumed to be a 32-bit signed integer. Your function should retu转载 2017-04-12 22:36:28 · 241 阅读 · 0 评论 -
(java)leetcode-45
Jump Game IIGiven 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.转载 2017-04-25 17:10:32 · 375 阅读 · 0 评论 -
(java)leetcode-73:Set Matrix Zeroes
Set Matrix ZeroesGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward s原创 2017-07-23 21:08:08 · 232 阅读 · 0 评论 -
(java)leetcode-60:Permutation Sequence
Permutation SequenceThe set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"1原创 2017-07-19 22:29:30 · 241 阅读 · 0 评论 -
(java)leetcode-84:Largest Rectangle in Histogram
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.Abov原创 2017-08-15 21:34:45 · 345 阅读 · 0 评论 -
(java)leetcode-79:Word Search
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 horizontally原创 2017-07-26 22:36:30 · 274 阅读 · 0 评论 -
(java)leetcode-78:Subsets
SubsetsGiven a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3],原创 2017-07-26 21:59:17 · 278 阅读 · 0 评论 -
(java)leetcode77:Combinations
CombinationsGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,原创 2017-07-26 21:23:10 · 292 阅读 · 0 评论 -
(java)leetcode-80:Remove Duplicates from Sorted Array II
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 function s原创 2017-08-03 11:12:27 · 342 阅读 · 0 评论 -
(java)leetcode-86:Partition List
Partition ListGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the原创 2017-08-16 21:57:40 · 287 阅读 · 0 评论 -
(java)leetcode-88:Merge Sorted Array
Merge Sorted ArrayGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to原创 2017-08-16 22:22:01 · 207 阅读 · 0 评论 -
(java)leetcode-75:Sort Colors
Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use原创 2017-07-24 22:30:00 · 233 阅读 · 0 评论 -
(java)leetcode74:Search a 2D Matrix
Search a 2D MatrixWrite 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 fir原创 2017-07-24 21:18:21 · 388 阅读 · 0 评论 -
(java)leetcode-50:Pow(x, n)
Pow(x, n) Implement pow(x, n).解题思路:一开始的想法就是简单的一个一个乘...果断TLE了。后面想了以下,应该得用递归的方式,每次都是平方这样来乘,计算复杂度也会降到log2(n)。然后又有一个问题就是n取 -2^32次方的时候,不能直接用n = -n。所以我用一个index来存储n的符号,这样在下一次递归,n = n/2的时候乘以index就原创 2017-07-08 11:21:52 · 210 阅读 · 0 评论 -
(java)leetcode-51:N-Queens
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 n-queens原创 2017-07-08 13:20:09 · 262 阅读 · 0 评论 -
(java)leetcode-53:Maximum Subarray
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 contiguous原创 2017-07-10 22:03:53 · 182 阅读 · 0 评论 -
(java)leetcode-55:Jump Game
Jump GameGiven 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.原创 2017-07-11 22:32:51 · 207 阅读 · 0 评论 -
(java)leetcode-54:Spiral Matrix
Spiral MatrixGiven 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 ],原创 2017-07-12 21:48:59 · 181 阅读 · 0 评论 -
(java)leetcode-43
Multiply StringsGiven two non-negative integers num1 andnum2 represented as strings, return the product of num1 andnum2.Note:The length of both num1 and num2 is Both num1 and num2 cont原创 2017-04-25 15:04:41 · 472 阅读 · 0 评论 -
(java)leetcode-42
Trapping Rain WaterGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0原创 2017-04-25 09:37:54 · 251 阅读 · 0 评论 -
(java)leetcode-20
Valid ParenthesesGiven a string containing just the characters'(',')', '{', '}', '[' and']', determine if the input string is valid.The brackets must close in the correct order,"()" and"()[]转载 2017-04-13 12:34:30 · 205 阅读 · 0 评论 -
(java)leetcode-19
Remove Nth Node From End of ListGiven a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing转载 2017-04-13 12:33:46 · 247 阅读 · 0 评论 -
(java)leetcode-17
Letter Combinations of a Phone NumberGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone butto转载 2017-04-13 12:32:43 · 206 阅读 · 0 评论 -
(java)leetcode-16
3Sum ClosestGiven 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 each input wo转载 2017-04-13 12:31:53 · 212 阅读 · 0 评论 -
(java)leetcode-15
3sumGiven 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-04-13 12:30:49 · 238 阅读 · 0 评论 -
(java)leetcode-14
Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.解题思路:大概就是先拿第一个作为前缀去匹配第二个,更新前缀,不断循环下去直到结束。有一个点就是,可以先比较前缀跟要匹配的String的长度大小,如果前缀长度大于要转载 2017-04-13 12:29:37 · 172 阅读 · 0 评论 -
(java)leetcode-11
Container With Most WaterGiven 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转载 2017-04-13 12:28:14 · 249 阅读 · 0 评论