leetcode
文章平均质量分 69
sea_px
这个作者很懒,什么都没留下…
展开
-
Leetcode62: Unique Paths
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 reach the原创 2016-10-17 00:59:21 · 158 阅读 · 0 评论 -
Leetcode397: Integer Replacement
Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum number o原创 2016-11-06 01:06:08 · 231 阅读 · 0 评论 -
Leetcode409: Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not con原创 2016-11-05 22:59:40 · 146 阅读 · 0 评论 -
Leetcode49: Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]题意:给出一个字原创 2016-10-02 23:53:37 · 338 阅读 · 0 评论 -
Leetcode58: 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 def原创 2016-10-01 13:38:31 · 149 阅读 · 0 评论 -
Leetcode5: Longest Palindromic Substring
5. Longest Palindromic SubstringGiven a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromi原创 2016-09-25 16:42:36 · 148 阅读 · 0 评论 -
Leetcode104: Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.题意:求一个数的最大深度,也就是从根节点到叶子节点的路径中拥有的最多的节原创 2016-09-23 23:48:02 · 212 阅读 · 0 评论 -
Leetocde51: N-Queens
The 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 puzzle.原创 2016-10-27 01:36:32 · 157 阅读 · 0 评论 -
Leetcode63: Unique Paths II
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 in the原创 2016-10-17 23:23:07 · 163 阅读 · 0 评论 -
Leetcode71: Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"题意:给出一个unix的完全路径,然后简化这个路径。主要的就是 /.. 表示返回上级目录, /. 表示在当前原创 2016-11-25 17:23:32 · 161 阅读 · 0 评论 -
Leetcode136: Single Number
Single Number 系列三道题目,解题思路都相似。136. Single NumberGiven an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear run原创 2016-11-15 20:12:43 · 158 阅读 · 0 评论 -
Leetcode38: 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-11-15 00:35:46 · 148 阅读 · 0 评论 -
Leetcode22: Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())原创 2016-10-30 22:03:49 · 199 阅读 · 0 评论 -
Leetcode35: Search Insert Position
Given 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 assume no duplicates in the array.原创 2016-10-29 22:06:30 · 150 阅读 · 0 评论 -
Leetcode329: Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside原创 2016-11-07 23:36:37 · 139 阅读 · 0 评论 -
Leetcode52: N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.题意:依然是N皇后问题,只不过在上次的八皇后问题中,是需要输出每个棋盘的布局的,而这一题只需要输出所有的解的数目即可。原创 2016-10-27 19:25:01 · 135 阅读 · 0 评论 -
Leetcode371: Sum of Two Integers
371. Sum of Two IntegersCalculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.题意:计算两个整数的值,不能用加法和减法。解答:一原创 2016-09-23 21:11:51 · 132 阅读 · 0 评论 -
Leetcode28: Implement strStr()
28. Implement strStr()Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题意:在一个字符串haystack中寻找有没有子字符串needle,要是有的话,返回第一次出现的位置,否则返回原创 2016-09-23 21:31:35 · 178 阅读 · 0 评论 -
Leetcode187: Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri原创 2016-11-04 00:24:50 · 202 阅读 · 0 评论 -
Leetcode139: Word Break
Given 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, givens = "leetcode",dict = ["leet"原创 2016-11-03 00:49:52 · 176 阅读 · 0 评论 -
Leetcode357: Count Numbers with Unique Digits
357. Count Numbers with Unique DigitsGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the原创 2016-09-23 21:44:04 · 169 阅读 · 0 评论 -
Leetcode373: Find K Pairs with Smallest Sums
373. Find K Pairs with Smallest SumsYou are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.Define a pair (u,v) which consists of one element from原创 2016-09-23 21:43:12 · 255 阅读 · 1 评论 -
Leetcode205: Isomorphic Strings
205. Isomorphic StringsGiven two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of原创 2016-09-23 21:33:23 · 246 阅读 · 0 评论 -
Leetcode9: Palindrome Number
Leetcode9:Palindrome NumberDetermine whether an integer is a palindrome. Do this without extra space.题意:判断一个数是不是回文数,并且不能使用额外的空间。解答:负数因为有负号所以不是回文数,所以在开始的时候就判断一下。因为不能使用额外的空间,所以这题的思路可原创 2016-09-23 21:34:57 · 166 阅读 · 0 评论 -
Leetcode169: Majority Element
Leetcode169:Majority ElementGiven 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-e原创 2016-09-23 21:36:47 · 201 阅读 · 0 评论 -
Leetcode215: Kth Largest Element in an Array
215. Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For e原创 2016-09-23 21:37:50 · 286 阅读 · 0 评论 -
Leetcode53: Maximum Subarray
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 c原创 2016-09-23 21:38:50 · 195 阅读 · 0 评论 -
Leetcode240: Search a 2D Matrix II
240. Search a 2D Matrix IIWrite 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 in原创 2016-09-23 21:40:00 · 254 阅读 · 0 评论 -
Leetcode378: Kth Smallest Element in a Sorted Matrix
378. Kth Smallest Element in a Sorted Matrix Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.原创 2016-09-23 21:41:15 · 254 阅读 · 0 评论 -
Leetcode392: Is Subsequence
392. Is SubsequenceGiven a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a原创 2016-09-23 21:42:12 · 143 阅读 · 0 评论 -
Leetcode179: Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2016-11-26 18:49:23 · 301 阅读 · 0 评论