
Leet Code --Array
lili616
这个作者很懒,什么都没留下…
展开
-
【Leet Code】73. Set Matrix Zeroes---Medium
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m原创 2015-11-10 11:10:10 · 488 阅读 · 0 评论 -
【Leet Code】229. Majority Element II---Medium
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.Hint:How many majority elements could it po原创 2015-11-30 14:44:34 · 255 阅读 · 0 评论 -
【Leet Code】53. Maximum Subarray---Medium
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,−1,2,1] ha原创 2015-11-26 11:07:10 · 305 阅读 · 0 评论 -
【Leet Code】152. Maximum Product Subarray---Medium
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges原创 2015-11-26 15:38:57 · 313 阅读 · 0 评论 -
【Leet Code】209. Minimum Size Subarray Sum---Medium
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 array [2,3原创 2015-11-23 15:25:05 · 284 阅读 · 0 评论 -
【Leet Code】238. Product of Array Except Self---Medium
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 and in O原创 2015-11-18 16:14:27 · 341 阅读 · 0 评论 -
【Leet Code】26. Remove Duplicates from Sorted Array---Easy
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 with原创 2015-11-18 14:58:24 · 290 阅读 · 0 评论 -
【Leet Code】48. Rotate Image---Medium
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?思路:该题目最大的难点就是理清二维数组的转换。对二维数组每圈每圈的处理(或者说一层一层的转)。理清原创 2015-11-18 14:52:45 · 311 阅读 · 0 评论 -
【Leet Code】80. Remove Duplicates from Sorted Array II---Medium
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 first fi原创 2015-11-18 15:20:30 · 285 阅读 · 0 评论 -
【Leet Code】74. Search a 2D Matrix---Medium
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 integer of each原创 2015-11-17 17:03:57 · 338 阅读 · 0 评论 -
【Leet Code】34. Search for a Ranged---Medium
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 not found原创 2015-11-17 16:10:06 · 335 阅读 · 0 评论 -
【Leet Code】33. Search in Rotated Sorted Array---Hard
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).You are given a target value to search. If found in the array retur原创 2015-11-16 17:51:52 · 260 阅读 · 0 评论 -
【Leet Code】268. Missing Number---Medium
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm sho原创 2015-11-23 13:28:37 · 313 阅读 · 0 评论 -
【Leet Code】283. Move Zeroes---Easy
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2015-11-23 10:45:46 · 240 阅读 · 0 评论 -
【Leet Code】81. Search in Rotated Sorted Array II---Medium
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 is in the原创 2015-11-17 10:29:16 · 279 阅读 · 0 评论 -
【Leet Code】35. Search Insert Position---Medium
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.原创 2015-11-16 16:49:42 · 269 阅读 · 0 评论 -
【Leet Code】31. Next Permutation---Medium
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 possible原创 2015-11-20 15:36:04 · 310 阅读 · 0 评论 -
【Leet Code】55. Jump Game---Medium
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.Determine i原创 2015-11-30 16:14:23 · 302 阅读 · 0 评论