![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Array
文章平均质量分 72
豆腐脑是咸的
这个作者很懒,什么都没留下…
展开
-
Plus One (Java)
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.Sourcepublic cla原创 2014-12-26 11:27:17 · 441 阅读 · 0 评论 -
Two Sum (Java)
Given 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, whe原创 2015-01-03 22:30:06 · 338 阅读 · 0 评论 -
3Sum Closest (Java)
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 exact原创 2015-01-04 14:39:38 · 415 阅读 · 0 评论 -
Maximum Product Subarray (Java)
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原创 2015-01-21 13:16:27 · 387 阅读 · 0 评论 -
4Sum (Java)
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:Element原创 2015-01-04 15:51:27 · 779 阅读 · 0 评论 -
Container With Most Water (Java)
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 (i, 0). Fin原创 2015-01-03 21:21:57 · 278 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II (Java)
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,原创 2015-01-03 16:22:09 · 404 阅读 · 0 评论 -
Sort Colors (Java)
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原创 2015-01-02 21:39:31 · 314 阅读 · 0 评论 -
Remove Duplicates from Sorted Array (Java)
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原创 2014-10-28 10:34:37 · 442 阅读 · 0 评论 -
Insert Interval (Java)
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.E原创 2015-02-06 19:53:47 · 458 阅读 · 0 评论 -
Construct Binary Tree from Preorder and Inorder Traversal (Java)
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.用中序找子树序列个数,在先序中找该长度子序列第一个元素作为子树rootSource/** *原创 2014-12-31 13:17:55 · 351 阅读 · 0 评论 -
Combination Sum (Java)
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.The same repeated number may be chosen from C unlimited numb原创 2015-01-19 11:34:17 · 282 阅读 · 0 评论 -
3Sum (Java)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c原创 2015-01-04 13:33:18 · 412 阅读 · 0 评论 -
Search in Rotated Sorted Array (Java)
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-01-23 11:35:45 · 320 阅读 · 0 评论 -
Search Insert Position (Java)
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-01-05 16:34:30 · 331 阅读 · 0 评论 -
Majority Element (Java)
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原创 2014-12-22 14:25:20 · 907 阅读 · 0 评论 -
Pascal's Triangle II (Java)
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?上一行从原创 2014-12-23 20:54:29 · 382 阅读 · 0 评论 -
Rotate Array (Java)
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 solutions as yo原创 2015-02-27 19:35:34 · 467 阅读 · 0 评论 -
Remove Element (Java)
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.S原创 2014-10-28 10:20:58 · 393 阅读 · 0 评论 -
Trapping Rain Water (Java)
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-01-24 11:50:33 · 310 阅读 · 0 评论 -
Median of Two Sorted Arrays (Java)
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)).参考:http://blog.csdn.net/yutianzui原创 2015-02-12 15:31:42 · 394 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array II (Java)
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unk原创 2015-01-24 10:48:31 · 310 阅读 · 0 评论 -
Search in Rotated Sorted Array II
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-01-23 18:08:01 · 278 阅读 · 0 评论 -
Search for a Range (Java)
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-01-05 21:42:41 · 495 阅读 · 0 评论 -
Find Peak Element (Java)
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, i原创 2015-01-05 21:42:19 · 374 阅读 · 0 评论 -
Search a 2D Matrix (Java)
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-01-05 17:10:10 · 258 阅读 · 0 评论 -
Subsets (Java)
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 exa原创 2015-01-19 09:39:52 · 634 阅读 · 0 评论 -
Minimum Path Sum (Java)
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 right at原创 2015-01-18 14:32:22 · 331 阅读 · 0 评论 -
Maximal Rectangle (Java)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.设一个数组表示从第一行开始遍历的当前列的高度,再用largest rectangle in histogram那道题的方法算最大面积。Sourcepubl原创 2015-02-05 10:33:20 · 361 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III (Java)
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may原创 2015-02-04 16:05:10 · 309 阅读 · 0 评论 -
Jump Game (Java)
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-01-16 21:10:47 · 571 阅读 · 0 评论 -
Next Permutation (Java)
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-01-16 20:48:10 · 757 阅读 · 0 评论 -
Set Matrix Zeroes (Java)
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-01-16 16:35:40 · 447 阅读 · 0 评论 -
First Missing Positive (Java)
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原创 2015-02-04 16:17:39 · 400 阅读 · 0 评论 -
Spiral Matrix II (Java)
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 ], [原创 2015-01-16 15:31:29 · 260 阅读 · 0 评论 -
Rotate Image (Java)
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?顺时针旋转90度就相当于先按对角线转置,再行内转置(第一个和最后一个换,第二个和倒数第二个换。。。)。原创 2015-01-16 16:52:17 · 664 阅读 · 0 评论 -
Spiral Matrix (Java)
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 ]]原创 2015-01-16 15:08:54 · 351 阅读 · 0 评论 -
Jump Game II (Java)
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 goal i原创 2015-01-29 17:16:22 · 372 阅读 · 0 评论 -
Longest Consecutive Sequence (Java)
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原创 2015-01-29 10:06:38 · 392 阅读 · 0 评论 -
Maximum Subarray (Java)
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-01-18 11:16:03 · 966 阅读 · 0 评论