![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Array
weixin_39145266
这个作者很懒,什么都没留下…
展开
-
41 First Missing Positive
Given an unsorted integer array, find the smallest missingpositive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,8,9,11,12]Output:...原创 2020-01-06 11:03:15 · 132 阅读 · 0 评论 -
1099 Two Sum Less Than K
1 题目Given an arrayAof integers andintegerK, return the maximumSsuch that there existsi < jwithA[i] + A[j] = SandS < K. If noi, jexist satisfying this equation, return -1.Example...原创 2019-12-05 08:15:50 · 111 阅读 · 0 评论 -
45 Jump Game II
1 题目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...原创 2019-10-01 08:52:53 · 52 阅读 · 0 评论 -
42 Trapping Rain Water
1 题目Givennnon-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.The above elevation map is represented b...原创 2019-11-24 13:30:30 · 55 阅读 · 0 评论 -
485 Max Consecutive Ones
1 题目Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecu...原创 2019-06-25 16:26:58 · 68 阅读 · 0 评论 -
229 Majority Element II
1 题目Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Note: The algorithm should run in linear time and in O(1) space.Example 1:Input: [3,2,3]Output: [3...原创 2019-04-23 13:00:48 · 176 阅读 · 0 评论 -
81 Search in Rotated Sorted Array II
1 题目Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).You are given a target value to search. If...原创 2019-04-15 14:42:11 · 53 阅读 · 0 评论 -
162 Find Peak Element
1 题目A peak element is an element that is greater than its neighbors.Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.The array may contain multiple...原创 2019-04-23 10:20:15 · 53 阅读 · 0 评论 -
88 Merge Sorted Array
1 题目Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:The number of elements initialized innums1andnums2aremandnrespectively. You may assume...原创 2019-04-26 18:15:11 · 197 阅读 · 0 评论 -
238 Product of Array Except Self
1 题目Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Example:Input: [1,2,3,4]Ou...原创 2019-04-22 16:15:36 · 55 阅读 · 0 评论 -
289 Game of Life
1 题目According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with...原创 2019-04-22 15:35:53 · 67 阅读 · 0 评论 -
228 Summary Ranges
1 题目Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]Explanation: 0,1,2 form a continuous rang...原创 2019-04-22 15:07:48 · 53 阅读 · 0 评论 -
121 Best Time to Buy and Sell Stock
1 题目Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the s...原创 2019-05-06 14:19:33 · 56 阅读 · 0 评论 -
122 Best Time to Buy and Sell Stock II
1 题目Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., ...原创 2019-05-06 14:34:02 · 69 阅读 · 0 评论 -
283 Move Zeroes
1 题目Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:...原创 2019-05-06 15:20:24 · 59 阅读 · 0 评论 -
189 Rotate Array
1 题目Given an array, rotate the array to the right byksteps, wherekis non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right...原创 2019-05-07 12:09:01 · 87 阅读 · 0 评论 -
380 Insert Delete GetRandom O(1)
1 题目Design a data structure that supports all following operations inaverageO(1)time.insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val fro...原创 2019-07-13 20:33:16 · 58 阅读 · 0 评论 -
746 Min Cost Climbing Stairs
1 题目On a staircase, thei-th step has some non-negative costcost[i]assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the t...原创 2019-08-03 11:24:11 · 51 阅读 · 0 评论 -
718 Maximum Length of Repeated Subarray
1 题目Given two integer arraysAandB, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The repeated su...原创 2019-08-03 12:25:23 · 56 阅读 · 0 评论 -
621 Task Scheduler
1 题目Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks. Tasks could be done without original order. Each task ...原创 2019-08-18 13:08:55 · 72 阅读 · 0 评论 -
1200 Minimum Absolute Difference
1 题目Given anarrayofdistinctintegersarr, find all pairs of elements with the minimum absolute difference of any two elements.Return a list of pairs in ascending order(with respect to pairs), ...原创 2019-09-24 10:05:49 · 138 阅读 · 0 评论 -
1 Two Sum
1 题目Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use the...原创 2019-10-02 04:46:06 · 54 阅读 · 0 评论 -
53 Maximum Subarray
1 题目Given an integer arraynums, find the contiguous subarray(containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Exp...原创 2019-04-26 10:01:06 · 63 阅读 · 0 评论 -
152 Maximum Product Subarray
1 题目Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [...原创 2019-04-09 16:04:02 · 65 阅读 · 0 评论 -
54 Spiral Matrix
1 题目Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.2 尝试解class Solution {public: vector<int> spiralOrder(vector<vector<i...原创 2019-03-29 09:18:50 · 60 阅读 · 0 评论 -
75 Sort Colors
1 题目Given an array withnobjects colored red, white or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use ...原创 2019-03-29 09:17:19 · 79 阅读 · 0 评论 -
55 Jump Game
1 题目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...原创 2019-03-29 09:19:33 · 47 阅读 · 0 评论 -
63 Unique Paths II
1 题目A robot is located at the top-left corner of amxngrid (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 ...原创 2019-03-29 09:16:42 · 58 阅读 · 0 评论 -
62 Unique Paths
1 题目A robot is located at the top-left corner of amxngrid (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 ...原创 2019-03-29 09:19:17 · 52 阅读 · 0 评论 -
209 Minimum Size Subarray Sum
1 题目Given an array ofnpositive integers and a positive integers, find the minimal length of acontiguoussubarray of which the sum ≥s. If there isn't one, return 0 instead.Example:Input: s...原创 2019-03-30 11:52:54 · 44 阅读 · 0 评论 -
48 Rotate Image
1 题目You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the imagein-place, which means you have to modify the input 2D ma...原创 2019-03-29 09:15:51 · 48 阅读 · 0 评论 -
56 Merge Intervals
1 题目Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] ov...原创 2019-03-29 09:17:13 · 46 阅读 · 0 评论 -
80 Remove Duplicates from Sorted Array II
1 题目Given a sorted arraynums, remove the duplicatesin-placesuch that duplicates appeared at mosttwiceand return the new length.Do not allocate extra space for another array, you must do this ...原创 2019-03-29 09:17:26 · 63 阅读 · 0 评论 -
64 Minimum Path Sum
1 题目Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or righ...原创 2019-03-29 09:18:18 · 49 阅读 · 0 评论 -
73 Set Matrix Zeroes
1 题目Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do itin-place.Example 1:Input: [ [1,1,1], [1,0,1], [1,1,1]]Output: [ [1,0,1], [0,0,0], [1,0,1]...原创 2019-03-29 09:18:33 · 48 阅读 · 0 评论 -
120 Triangle
1 题目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], ...原创 2019-04-08 14:26:44 · 124 阅读 · 0 评论 -
90 Subsets II
1 题目Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: [1...原创 2019-04-11 19:33:27 · 56 阅读 · 0 评论 -
153 Find Minimum in Rotated Sorted Array
1 题目Suppose an array sorted in ascending order 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 assum...原创 2019-04-08 11:55:30 · 59 阅读 · 0 评论 -
106 Construct Binary Tree from Inorder and Postorder Traversal
1 题目Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, giveninorder =[9,3,15,20,7]postorde...原创 2019-04-01 21:37:45 · 47 阅读 · 0 评论 -
105 Construct Binary Tree from Preorder and Inorder Traversal
1 题目Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, givenpreorder =[3,9,20,15,7]inorder ...原创 2019-04-01 21:35:46 · 52 阅读 · 0 评论