leetcode-array
永不_言败
这个作者很懒,什么都没留下…
展开
-
【leetcode】Array——word search(79)
题目:Given board =[ ['A','B','C','E'], ['S','F','C','S'], ['A','D','E','E']]word = "ABCCED", -> returns true,word = "SEE", -> returns true,原创 2016-02-11 22:29:35 · 437 阅读 · 0 评论 -
【leetcode】Array——Contains Duplicate II(219)
题目:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k原创 2016-03-13 10:16:49 · 385 阅读 · 0 评论 -
【leetcode】Array——Contains Duplicate(217)
题目: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 ele原创 2016-03-12 22:22:47 · 301 阅读 · 0 评论 -
【leetcode】Array——Jump Game2(45)
题目: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-03-12 21:48:53 · 306 阅读 · 0 评论 -
【leetcode】Array——Rotate Array(189)
题目: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 soluti原创 2016-02-27 20:50:04 · 217 阅读 · 0 评论 -
【leetcode】Array——Rotate Image(48)
题目: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?思路: 旋转处理分两步:1.行元素交换 2.对称交换原创 2016-02-27 18:10:59 · 212 阅读 · 0 评论 -
【leetcode】Array——Search a 2D Matrix(74)
题目: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 intege原创 2016-02-27 17:04:45 · 197 阅读 · 0 评论 -
【leetcode】Array——Jump Game(55)
题目: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.De原创 2016-03-12 11:57:15 · 233 阅读 · 0 评论 -
【leetcode】Array——Search for a Range(34)
题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is n原创 2016-02-26 13:31:47 · 359 阅读 · 0 评论 -
【leetcode】Array——Longest Consecutive Sequence(128)
题目:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is原创 2016-03-10 22:04:07 · 224 阅读 · 0 评论 -
【leetcode】Array——Construct Binary Tree from Preorder and Inorder Traversal(105)
题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:使用递归。preorder[0]是整个tree的root,在inerder中定位roo原创 2016-03-21 22:56:43 · 210 阅读 · 0 评论 -
【leetcode】Array——Trapping Rain Water(42)
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,2,1],原创 2016-02-11 22:38:47 · 223 阅读 · 0 评论 -
【leetcode】Array——Remove Duplicates from Sorted Array(26)
题目: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 p原创 2016-02-28 10:14:36 · 190 阅读 · 0 评论 -
【leetcode】Array——Remove Duplicates from Sorted Array II(80)
题目: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 the原创 2016-02-28 10:59:50 · 171 阅读 · 0 评论 -
【leetcode】Array——3Sum Closest(16)
题目:Given 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 would have原创 2016-03-29 10:58:13 · 331 阅读 · 0 评论 -
【leetcode】Array——4Sum(18)
题目:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:原创 2016-03-28 21:28:21 · 310 阅读 · 0 评论 -
【leetcode】Array——Best Time to Buy and Sell Stock I/II/III
Best Time to Buy and Sell Stock题目:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, b原创 2016-03-26 15:31:49 · 310 阅读 · 0 评论 -
【leetcode】Array——Combination Sum I/II/III
Combination Sum题目:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.A solution set is: [7] [2, 2, 3]原创 2016-03-26 10:42:48 · 248 阅读 · 0 评论 -
【leetcode】Array—— Pascal's Triangle and Pascal's Triangle II(118/119)
题目:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]思路:经典的DP代码:原创 2016-02-29 22:39:23 · 200 阅读 · 0 评论 -
【leetcode】Array——Search in Rotated Sorted Array II(81)
题目:Follow 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 target原创 2016-02-26 11:54:11 · 224 阅读 · 0 评论 -
【leetcode】Array——Insert Interval(57)
题目:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Ex原创 2016-03-13 21:04:09 · 334 阅读 · 0 评论 -
【leetcode】Array—— Plus One(66)
题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.[1,2,3]->[1,2原创 2016-02-29 14:48:35 · 225 阅读 · 0 评论 -
【leetcode】Array—— Product of Array Except Self(238)
题目:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division a原创 2016-02-29 14:17:41 · 228 阅读 · 0 评论 -
【leetcode】Array——Maximal Rectangle(85)
题目:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路:DP按行扫描,维护三个数组,height、left、right,记录包含当前元素matrix[i][j]所在列‘1’的高度(height),以及左原创 2016-03-10 09:18:26 · 263 阅读 · 0 评论 -
【leetcode】Array——Largest Rectangle in Histogram(84)
题目: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.For example,Given heights = [转载 2016-03-13 13:26:17 · 264 阅读 · 0 评论 -
【leetcode】Array——Find Minimum in Rotated Sorted Array II(154)
题目:前一道题链接:http://blog.csdn.net/u013127687/article/details/50935939Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexit原创 2016-03-20 13:34:43 · 202 阅读 · 0 评论 -
【leetcode】Array——Find Minimum in Rotated Sorted Array(153)
题目: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 exi原创 2016-03-20 12:05:17 · 313 阅读 · 0 评论 -
【leetcode】Array——Search Insert Position(35)
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-02-11 22:42:12 · 246 阅读 · 0 评论 -
【leetcode】Array—— Minimum Size Subarray Sum(209)
题目:Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the a原创 2016-03-03 10:28:53 · 287 阅读 · 0 评论 -
【leetcode】Array——Unique Paths II(63)
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 grid.原创 2016-02-11 22:36:24 · 228 阅读 · 0 评论 -
【leetcode】Array——Unique Paths(62)
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 bo原创 2016-02-11 22:31:07 · 216 阅读 · 0 评论 -
【leetcode】Array——Spiral MatrixII(59)
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, 9, 4 ],原创 2016-02-11 22:43:07 · 205 阅读 · 0 评论 -
【leetcode】Array—— Set Matrix Zeroes(73)
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place。Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad ide原创 2016-02-11 22:41:04 · 261 阅读 · 0 评论 -
【leetcode】Array——Sort Color(75)
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 integers 0,原创 2016-02-11 22:40:25 · 278 阅读 · 0 评论 -
【leetcode】Array——SubsetsII(90)
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplic原创 2016-02-11 22:40:01 · 302 阅读 · 0 评论 -
【leetcode】Array——Subsets(78)
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.For exampl原创 2016-02-11 22:39:33 · 312 阅读 · 0 评论 -
【leetcode】Array——Triangle(120)
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], [3,4], [6原创 2016-02-11 22:38:16 · 273 阅读 · 0 评论 -
【leetcode】Array——Spiral Matrix(54)
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, 9 ]]Y原创 2016-02-11 22:41:46 · 224 阅读 · 0 评论 -
【leetcode】Array—— Minimum Path Sum(64)
题目: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原创 2016-03-03 14:08:39 · 208 阅读 · 0 评论 -
【leetcode】Array——Majority Element II(229)
题目:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.思路:在Majority Element中,了解了Moore Voting算法。该题原创 2016-03-08 15:33:01 · 299 阅读 · 0 评论