leetcode
文章平均质量分 52
buppt
公众号:BUPPT
展开
-
【leetcode】第14题 Longest Common Prefix 题目+解析+代码
【题目】Write a function to find the longest common prefix string amongst an array of strings.【解析】这道题比较简单,就是找出string数组中所有字符串的最大共同前缀。【代码】public class Solution { public String longestCommo原创 2017-08-09 17:58:55 · 391 阅读 · 0 评论 -
【leetcode】第66题 Plus One 题目+解析+JAVA代码
【题目】Given a non-negative integer represented as a non-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-08-30 23:13:16 · 620 阅读 · 0 评论 -
【leetcode】第64题 Minimum Path Sum 题目+解析+JAVA代码
【题目】Given 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 either down or原创 2017-08-30 22:11:49 · 341 阅读 · 0 评论 -
【leetcode】第63题 Unique Paths II 题目+解析+JAVA代码
【题目】Follow 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 respectively原创 2017-08-30 22:00:56 · 418 阅读 · 0 评论 -
【leetcode】第62题 Unique Paths 题目+解析+JAVA代码
【题目】A 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 to原创 2017-08-30 21:55:51 · 355 阅读 · 0 评论 -
【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原创 2017-08-09 11:29:20 · 752 阅读 · 0 评论 -
【leetcode】第70题 Climbing Stairs 题目+解析+JAVA代码
【题目】You 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 will be原创 2017-09-11 17:55:51 · 419 阅读 · 0 评论 -
【leetcode】第73题 Set Matrix Zeroes 题目+解析+JAVA代码
【题目】Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.【解析】一个m*n的矩阵,如果有一个元素是0,就把它所在的行和列都设置为0.我们用第一行和第一列储存改行或列是否有0,最后再将第一行和第一列是0的行和列全部替换为0.【代码】原创 2017-09-11 18:12:51 · 318 阅读 · 0 评论 -
【leetcode】第72题 Edit Distance 题目+解析+JAVA代码
【题目】Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted原创 2017-09-11 18:00:17 · 442 阅读 · 0 评论 -
【leetcode】第74题 Search a 2D Matrix 题目+解析+JAVA代码
【题目】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 integ原创 2017-09-11 18:18:15 · 625 阅读 · 0 评论 -
【leetcode】第75题 Sort Colors 题目+解析+JAVA代码
【题目】Given 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 the原创 2017-09-11 18:21:55 · 355 阅读 · 0 评论 -
【leetcode】第77题 Combinations 题目+解析+JAVA代码
【题目】Given 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,3],原创 2017-09-11 18:26:31 · 562 阅读 · 0 评论 -
【leetcode】第78题 Subsets 题目+解析+JAVA代码
【题目】Given 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:[ [原创 2017-09-11 18:29:30 · 845 阅读 · 0 评论 -
【leetcode】第67题 Add Binary 题目+解析+JAVA代码
【题目】Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".【解析】字符串类型的二进制加法,从后往前加,再设置一个进位就ok了。【代码】public String addBinary(Stri原创 2017-09-02 21:36:03 · 436 阅读 · 0 评论 -
【leetcode】第69题 Sqrt(x) 题目+解析+JAVA代码
【题目】Implement int sqrt(int x).Compute and return the square root of x.【解析】求平方根,注意因为是int型,所以只用求到整数位即可。【代码】public int mySqrt(int x) { if(x==0) return 0;原创 2017-09-02 22:33:33 · 315 阅读 · 0 评论 -
【leetcode】第105题Construct Binary Tree from Preorder and Inorder Traversal
题目很简单,就是知道前序遍历和中序遍历让我们推二叉树的结构。首先我们要知道前序遍历是先访问根节点,再访问左子树,再访问右子树。中序遍历先访问左子树,再访问根节点,最后访问右子树。例如一棵树如下: A B C D E F G前序遍历结果是A BDE CFG 中序遍历结果是DBE A FCG我用空格分开了根节点、左子树和右子树。然后原创 2018-01-07 23:01:32 · 904 阅读 · 0 评论 -
【leetcode】第65题 Valid Number 这道题用JS代码超级简单=-=
【题目】Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to原创 2017-08-30 22:39:51 · 342 阅读 · 0 评论 -
【leetcode】第59题 Spiral Matrix II 题目+解析+代码
【题目】Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8,原创 2017-08-27 10:34:06 · 334 阅读 · 0 评论 -
【leetcode】第20题 Valid Parentheses 题目+解析+代码
【题目】Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2017-08-09 23:06:41 · 411 阅读 · 0 评论 -
【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.【解析】要求实现strStr()函数。返回在子字符串needle在字符串haystack中第一次出现的位原创 2017-08-19 12:42:04 · 418 阅读 · 0 评论 -
【leetcode】第30题 Substring with Concatenation of All Words
LeetCode30-----------Substring with Concatenation of All Words看题目都有些费劲,要不是看了几组Custom Testcase才知道题意,顺便说一句Custom Testcase这个功能在调试的时候真的非常实用。题目意思:给定一个字串不妨称为母串S,和一组单词,他们保存在一个string的顺序容器Words中,并且满足一个条件转载 2017-08-19 13:04:20 · 377 阅读 · 0 评论 -
【leetcode】第32题 Longest Valid Parentheses 题目+解析+代码
【题目】Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring i原创 2017-08-19 19:49:04 · 297 阅读 · 0 评论 -
【leetcode】第36题 Valid Sudoku 题目+解析+代码
【题目】Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially f原创 2017-08-19 21:13:00 · 435 阅读 · 0 评论 -
【leetcode】第38题 Count and Say 题目+解析+代码
【题目】The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.原创 2017-08-20 11:36:36 · 898 阅读 · 0 评论 -
【leetcode】第47题 Permutations II(非递归法)题目+解析+代码
【题目】Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[ [1,1,2], [1,2,原创 2017-08-22 15:00:21 · 336 阅读 · 0 评论 -
【leetcode】第46题 Permutations(递归法)题目+解析+代码
【题目】Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],原创 2017-08-22 12:40:27 · 679 阅读 · 0 评论 -
【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?【解析】旋转矩阵discuss里一共有三个思想:1、上下对称后,对角线对称。原创 2017-08-22 15:28:11 · 327 阅读 · 0 评论 -
【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,原创 2017-08-26 10:53:55 · 473 阅读 · 0 评论 -
【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,原创 2017-08-26 11:36:00 · 477 阅读 · 0 评论 -
【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 in原创 2017-08-18 16:04:19 · 872 阅读 · 0 评论 -
【leetcode】第55题 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.D原创 2017-08-26 17:42:44 · 480 阅读 · 0 评论 -
【leetcode】第44题 Wildcard Matching 题目+解析+代码
【题目】Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching shou原创 2017-08-23 12:08:33 · 452 阅读 · 0 评论 -
【leetcode】第56题 Merge Intervals 题目+解析+代码
【题目】Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].【解析】本题意思是要把给出的区间集合合并,输出合并后的区间集合。思路不难,主要是原创 2017-08-26 23:19:45 · 526 阅读 · 0 评论 -
【leetcode】第68题 Text Justification 解析及java代码
这题164赞538踩。。好惨就是输入一个字符串数组,数组里每一项是一个单词。再输入一个maxWidth,这个长度是输出每一行的字符串长度。要求是每个单词和每个单词之间最少一个空格,如果一行最后剩余的位置不能再放一个单词,就把这一行后面的空格平均分到前面几个单词中间。 如果这一行只有一个单词或者这是最后一行,那么就不用管后面的空格了(但是还是要补充空格到maxWidth)。我的思路比较...原创 2018-07-14 21:57:43 · 603 阅读 · 0 评论