LeetCode
文章平均质量分 65
Jassy1994
这个作者很懒,什么都没留下…
展开
-
LeetCode 第三题(Longest Substring Without Repeating Characters)Java
原题:Given a string, find the length of the longest substring without repeating characters.第一次做采取的是暴力的依次搜索每一个位置上的最长不重复子串,时间复杂度为O(N*N);这次在看了左老师的视频后,采用一次遍历,得到结果;算法思路:当前位置的最长不重复子串长度与上一位置的原创 2016-10-21 11:40:19 · 708 阅读 · 0 评论 -
LeetCode 55(Jump Game) Java
原题: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.Determin原创 2016-11-14 12:01:07 · 439 阅读 · 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 inte原创 2016-12-01 09:41:24 · 393 阅读 · 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 properties1. Integers in each row are sorted from left to right.2. The first integer o原创 2016-12-01 09:33:45 · 407 阅读 · 0 评论 -
LeetCode 97(Interleaving String)Java
原题:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.给定3个字符串,判断s3是否可以由s1和s2交错组成;例如:s1="aa",s2="bc",s3="abca";s3可以由s1和s2交错组成;思路:很多字符串问题某一位置的解会与它上一位置的解有关,这种情原创 2016-12-01 10:17:03 · 476 阅读 · 0 评论 -
LeetCode 84 (Largest Rectangle in Histogram)java
原题:Given 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-11-24 11:27:57 · 347 阅读 · 0 评论 -
LeetCode 86(Partition List)java
原题:Given 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 nodes in原创 2016-11-24 16:02:27 · 1720 阅读 · 0 评论 -
LeetCode 89(Gray Code)java
原题:The 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 sequence原创 2016-11-25 10:16:42 · 425 阅读 · 0 评论 -
LeetCode 85 (Maximal-Rectangle)java
原题:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:求给定矩阵中全为1的最大长方形的面积;昨天A原创 2016-11-25 10:48:36 · 573 阅读 · 0 评论 -
LeetCode 54 (Spiral Matrix)Java
原题:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.旋转打印矩阵;思路:我采取的是循环,应该考虑递归实现会清晰一些,之后考虑递归;去除特殊情况:最后一行是奇数应该怎么输出;代码:public class Sol原创 2016-11-14 11:54:23 · 327 阅读 · 0 评论 -
LeetCode 53(Maximum Subarray)Java
原题:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.寻找子数组的最大值思路:对于一个确定的子数组最大值来说,它一定满足:以其开头左边元素为末尾的任何一段子数组的和都小于0;若存在一段大于0的,则最大子数组就可以延长;所以设置一原创 2016-11-14 11:44:16 · 312 阅读 · 0 评论 -
LeetCode 第二十六题(Remove Duplicates from Sorted Array) java
原题:Given 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 another array, you must do this in place原创 2016-11-02 11:25:17 · 277 阅读 · 0 评论 -
LeetCode 第三十一题(Next Permutation) java
原题: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 possi原创 2016-11-03 11:06:07 · 452 阅读 · 0 评论 -
LeetCode 第四十二题(Trapping Rain Water) Java
原题:Given 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,1,0,2,1,0,1,3,2,1原创 2016-11-07 21:07:13 · 298 阅读 · 0 评论 -
LeetCode 第四十三题(Multiply Strings)Java
原题:Given two numbers represented as strings, return multiplication of the numbers as a string.思路:正是将我们学过的计算乘法的方法利用算法实现:1. 从某数最低位开始,计算它与另一个数相乘的结果,用一个数组记录下来;2. 遍历该数每一位置,每次都做第一步的工作;3. 处理和数组中的进位,得原创 2016-11-08 10:53:35 · 355 阅读 · 0 评论 -
LeetCode 第四十五题(Jump Game II)Java
原题: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.Your原创 2016-11-08 20:35:13 · 349 阅读 · 0 评论 -
LeetCode 第46,47题(Permutations)Java
原题:Given a collection of distinct numbers, return all possible permutations.第四十六题允许重复,四十七题不允许;在解法上有相似的地方;思路:这道全排列问题可以递归地去做,先确定一个值,对剩下的进行递归;实际上是一道关于深度优先搜索算法的题目;参考了这一篇博客:http://blog.csdn.net原创 2016-11-08 20:52:24 · 611 阅读 · 0 评论 -
LeetCode 第九题(Palindrome Number)Java
原题:Determine whether an integer is a palindrome. Do this without extra space.解题思路:1.回文数即正着读和反着读结果相同的数,所以,负数不是回文数;2.个位数都是回文数;3.对于一个数,想要确定它是否为回文数,可以先得到该数的颠倒位置的数(见LeetCode第七题),再判断两数是否相等,若相等,则原创 2016-10-20 16:13:04 · 302 阅读 · 0 评论 -
LeetCode 第二十九题(Divide Two Integers)Java
原题:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.计算两数相除的商;思路:将被除数dividend表示为除数的多项式:dividend = 2^i * divisor + 2^(i-1) * divi原创 2016-11-08 10:44:05 · 449 阅读 · 0 评论 -
LeetCode 50 Pow(x, n) Java
原题:Implement pow(x, n);思路:求幂次采用递归的方法;myPow( x , n )=myPow( x , n/2 ) * myPow( x , n/2 );考虑奇数次幂和偶数次幂相差一次;考虑负数次幂等于正数次幂的倒数;之后去除特殊情况:1. 幂次是Integer.MIN_VALUE不能直接取负;2. 除数不能为0;3. 幂次最大值不能超过Dou原创 2016-11-14 11:22:41 · 364 阅读 · 0 评论 -
LeetCode 79(Word Search)java
原题: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 vertica原创 2017-01-04 22:54:22 · 2360 阅读 · 0 评论