
Array
文章平均质量分 69
ljffdream
这个作者很懒,什么都没留下…
展开
-
【Leetcode】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转载 2015-01-06 17:05:05 · 343 阅读 · 0 评论 -
【Leetcode】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 is9534330.Note: The result may转载 2015-08-03 21:38:34 · 297 阅读 · 0 评论 -
【Leetcode】Spiral Matrix
【题目】Given aninteger n,generate a square matrix filled with elements from 1 to n2 inspiral order.For example,Given n = 3,Youshould return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ]转载 2015-09-01 00:52:31 · 259 阅读 · 0 评论 -
【Leetcode】Unique paths 2
【题目】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转载 2015-09-01 10:04:16 · 221 阅读 · 0 评论 -
【Leetcode】Jump Game 1,2
【题目】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.You转载 2015-08-26 10:27:45 · 302 阅读 · 0 评论 -
【Leetcode】Merge intervals
【题目】Given a collection ofintervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].【思路】思路就是,先对进来的这一个list 的inteval进行比较,排序,排序的时候转载 2015-08-31 22:31:50 · 258 阅读 · 0 评论 -
[Leetcode]Word Search
[timu]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 horizontal转载 2015-09-02 07:51:04 · 288 阅读 · 0 评论 -
【Leetcode】Minimum sum path
【题目】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转载 2015-09-01 11:30:47 · 234 阅读 · 0 评论 -
【Leetcode】maximum Rangtangle in 2D matrix
【题目】Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.【思路】只能说不明觉厉:The DP solution proceeds row by row, starting f转载 2015-09-02 11:10:29 · 328 阅读 · 0 评论 -
[Leetcode]Remove duplicates
[timu]Follow 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 should return length = 5, with转载 2015-09-02 08:10:54 · 300 阅读 · 0 评论 -
【Leetcode】Set matrix zeros
【题目】【思路】My idea is simple: store states of each row in the first of that row, and store states of each column in the first of that column. Because the state of row0 and the state of column0转载 2015-09-01 23:10:47 · 354 阅读 · 0 评论 -
[Leetcode]Search a 2D matrix
[timu]Search a 2D MatrixTotal Accepted: 52191 Total Submissions: 164580Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the followin原创 2015-09-02 03:29:54 · 290 阅读 · 0 评论 -
【Leetcode】Largest Ractangular
【题目】Largest Rectangle in Histogram Total Accepted: 42804 Total Submissions: 188970My SubmissionsQuestion Solution Given n non-negative integers representing the histogram转载 2015-09-02 11:02:12 · 304 阅读 · 0 评论 -
【Leetcode】subsets2T
【题目】Given a collection of integers thatmight contain duplicates, nums,return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contai转载 2015-09-03 00:39:53 · 323 阅读 · 0 评论 -
【Leetcode】Construct Binary Tree From Inorder and Preorder/Postorder Traversal
【题目】Given preorder and inorder traversal of a tree, construct the binary tree.【思路】Hint:A good way to attempt this question is to work backwards. Approach this question by drawing a binary转载 2015-09-03 02:13:50 · 542 阅读 · 0 评论 -
【Leetcode】Construct binary tree from inorder and postorder traversal
【题目】Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.【思路】pretty similar with that转载 2015-09-03 03:10:58 · 411 阅读 · 0 评论 -
【Leetcode】Triangle
【题目】Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [转载 2015-09-04 11:08:48 · 366 阅读 · 0 评论 -
[Leetcode]sort Color
[timu] Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adja转载 2015-09-02 03:55:21 · 271 阅读 · 0 评论 -
【Leetcode】Rain trapping
【题目】 Given n non-negative integers representing anelevation map where the width of each bar is 1, compute how much water it isable to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1转载 2015-08-25 22:18:54 · 356 阅读 · 0 评论 -
【Leetcode】Rotate Image
【题目】You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).【思路】The idea was firstly transpose the matrix and then flip it symmetrically.转载 2015-08-26 14:31:59 · 269 阅读 · 0 评论 -
【Leetcode】First Missing Positive
【题目】Given an unsortedinteger array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and us转载 2015-08-24 23:21:41 · 299 阅读 · 0 评论 -
【LeetCode】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 th原创 2014-12-05 17:05:33 · 263 阅读 · 0 评论 -
【Leetcode】Sort Colors
【题目】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原创 2014-12-07 10:20:07 · 355 阅读 · 0 评论 -
【LeetCode】Majority Numbers
【题目】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-empty and the majorit原创 2014-12-24 10:22:30 · 316 阅读 · 0 评论 -
【Leetcode】Find peak numbers
【题目】A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multipl原创 2015-04-08 10:35:46 · 384 阅读 · 0 评论 -
【Leetcode】Container with most water
【题目】Given 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 (i, ai) and原创 2015-04-09 01:00:59 · 334 阅读 · 0 评论 -
[Leetcode]Basic calculator 1 and 2
[题目]Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers an转载 2015-06-19 10:50:56 · 459 阅读 · 0 评论 -
【Leetcode】Contains Duplicate 1 and 2
【题目】Given 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 return false if every el原创 2015-06-20 20:50:11 · 273 阅读 · 0 评论 -
【Leetcode】Summary Ranges
【题目】Given 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"].Credits:Special thanks to @jianchao.l转载 2015-06-27 20:30:48 · 413 阅读 · 0 评论 -
[Leetcode]Median of two sorted array
[题目]There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).[分析][code转载 2015-06-11 09:59:15 · 618 阅读 · 0 评论 -
[Leetcode]Sorted in rotated Array 2
[题目] medianFollow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given tar转载 2015-06-12 09:13:22 · 311 阅读 · 0 评论 -
【LeetCode】Find Minimum In Rotated Sorted Array 1 and 2
【题目】Suppose 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).Find the minimum element.You may assume no duplicate转载 2015-01-05 10:20:39 · 305 阅读 · 0 评论 -
【leetcode】Rotate Array
【题目】Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solut翻译 2015-07-02 23:21:57 · 294 阅读 · 0 评论 -
【Leetcode】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 duplicate subsets.转载 2015-07-12 21:17:00 · 361 阅读 · 0 评论 -
【Leetcode】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 parti转载 2015-07-05 10:37:08 · 381 阅读 · 0 评论 -
【Leetcode】Search for a range
【题目】【思路】The problem can be simply broken down as two binary searches for the begining and end of the range, respectively:First let's find the left boundary of the range. We ini转载 2015-08-23 21:09:39 · 292 阅读 · 0 评论 -
【Leetcode】Combination sum 1,2
【题目】【分析】首先,先sort,如果target > 0:【代码】using recursive 这恐怕的 O(n2)...过程:before recursion : [2]before recursion : [2, 2]before recursion : [2, 2, 2]after recursion and remove :转载 2015-08-24 16:47:10 · 355 阅读 · 0 评论 -
【Leetcode】Longest Palindrome
【题目】Given 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 palindromic substring.【思路】中心检测转载 2015-09-09 10:25:31 · 422 阅读 · 0 评论