
leetcode array
proudmore
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode Remove Duplicates from Sorted Array II
Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,2,3].[cod原创 2015-02-22 14:42:28 · 138 阅读 · 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 integers 0, 1,原创 2015-03-12 04:46:01 · 201 阅读 · 0 评论 -
Leetcode Combinations
saaaasda原创 2015-03-12 08:26:54 · 190 阅读 · 0 评论 -
Leetcode letter combinations of a phone number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string “23”原创 2015-03-12 09:07:38 · 177 阅读 · 0 评论 -
Leetcode First missing positive
Given an unsorted integer 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 uses constant space.[c原创 2015-03-12 02:19:20 · 142 阅读 · 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 the array.Here原创 2015-03-12 05:12:19 · 146 阅读 · 0 评论 -
Leetcode Search for a range
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 in the ar原创 2015-03-12 04:54:55 · 188 阅读 · 0 评论 -
Leetcode Search a 2D matrix
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 row is原创 2015-03-12 05:24:22 · 178 阅读 · 0 评论 -
Leetcode Subsets I, II
subsets Given a set of distinct integers, S, return all possible subsets.Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example,原创 2015-03-12 07:55:26 · 220 阅读 · 0 评论 -
Leetcode 智力trick题
candyThere are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least o原创 2015-03-04 07:13:48 · 223 阅读 · 0 评论 -
Leetcode Search in rotated sorted array I, II
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 return its in原创 2015-03-24 09:48:20 · 147 阅读 · 0 评论 -
Leetcode Pascal's triangle I, II
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]][code]public class Solution { p原创 2015-03-24 14:13:25 · 172 阅读 · 0 评论 -
Leetcode Maximum products subarray
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 largest produ原创 2015-04-01 06:54:26 · 159 阅读 · 0 评论 -
Leetcode Find peak element
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 multiple peaks, in that case原创 2015-04-10 02:18:46 · 187 阅读 · 0 评论 -
Leetcode Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].题中给出的intervals实际上是已经按start排好序的, otherwise,需要implements原创 2015-04-14 08:34:35 · 154 阅读 · 0 评论 -
Leetcode Majority element
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 majority element alway原创 2015-03-21 05:21:32 · 180 阅读 · 0 评论 -
Leetcode Largest rectangle in histogram
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.算法: 1. if height[i]>=stack.peek(), push 2.原创 2015-03-28 01:45:25 · 163 阅读 · 0 评论 -
Leetcode Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.**[code]**Remove Duplicates from原创 2015-02-22 14:51:08 · 145 阅读 · 0 评论 -
Leetcode Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1->2原创 2015-02-22 15:05:52 · 183 阅读 · 0 评论 -
Leetcode Remove duplicates from sorted array
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 cons原创 2015-02-22 14:35:30 · 149 阅读 · 0 评论 -
Leetcode Permutation 问题
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 orde原创 2015-02-26 14:31:41 · 226 阅读 · 0 评论 -
Leetcode NSum 问题
Two SumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, w原创 2015-02-26 08:58:23 · 387 阅读 · 0 评论 -
Leetcode Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn’t matter what you leave beyond the new length.[code]publ原创 2015-02-26 09:06:43 · 140 阅读 · 0 评论 -
Leetcode Longest Consecutive Sequence
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 [1, 2, 3, 4].原创 2015-02-25 03:40:19 · 172 阅读 · 0 评论 -
Leetcode Median of Two Sorted Arrays
There are two sorted arrays A and B 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]public class Solution { publ原创 2015-02-25 07:28:14 · 253 阅读 · 1 评论 -
Leetcode Rotate image
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?[code]public class Solution { public void rotate(int[][]原创 2015-02-27 07:32:32 · 158 阅读 · 0 评论 -
Leetcode Set matrix zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.public class Solution { public void setZeroes(int[][] matrix) { if(matrix==null)return;原创 2015-02-28 06:58:48 · 203 阅读 · 0 评论 -
Leetcode Trapping rain water
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]原创 2015-02-27 07:01:14 · 193 阅读 · 0 评论 -
Leetcode Sudoku 问题
Valid sudokuDetermine 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 ‘.’.public class Solut原创 2015-02-27 06:34:38 · 172 阅读 · 0 评论 -
Leetcode Gray code
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 of gray原创 2015-02-27 13:48:33 · 167 阅读 · 0 评论 -
Leetcode Maximal rectangle
public class Solution { public int maximalRectangle(char[][] matrix) { if(matrix==null || matrix.length==0 || matrix[0].length==0)return 0; int m=matrix.length, n=matrix[0].length;原创 2015-03-28 05:04:50 · 168 阅读 · 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].这题要求in-place。 思路和reverse words in a string II 一样: 矩阵转置原创 2015-05-07 13:44:25 · 142 阅读 · 0 评论