![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
array
Vendredimatin
这个作者很懒,什么都没留下…
展开
-
leetcode 268. Missing Number
268. Missing NumberGiven an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.Example 1:Input: [3,0,1]Output: 2Example 2:Input: [9,6,4,2,3...原创 2019-05-13 20:59:38 · 114 阅读 · 0 评论 -
leetcode 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the int...原创 2019-06-12 11:33:42 · 107 阅读 · 0 评论 -
leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
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 = [9,3,15,...原创 2019-06-12 11:35:21 · 95 阅读 · 0 评论 -
Leetcode 56. Merge Intervals
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] overlaps, m...原创 2019-06-18 10:45:00 · 119 阅读 · 0 评论 -
leetcode 34. Find First and Last Position of Element in Sorted Array
Given an array of integers nums sorted in ascending order, 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 t...原创 2019-06-18 10:53:10 · 153 阅读 · 0 评论 -
leetcode 33.Search in Rotated Sorted Array
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]).You are given a target value to search. If found in...原创 2019-06-18 11:13:11 · 141 阅读 · 0 评论 -
Leetcode 55. Jump Game
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 if you ...原创 2019-06-22 15:33:39 · 203 阅读 · 0 评论 -
leetcode 54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]Example...原创 2019-06-22 15:34:49 · 200 阅读 · 0 评论 -
leetcode 152. Maximum Product Subarray
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: [2,3] has ...原创 2019-06-22 15:37:36 · 142 阅读 · 0 评论 -
leetcode 15. 3Sum
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not contai...原创 2019-06-22 15:39:02 · 146 阅读 · 0 评论 -
leetcode 42. 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.Example:Input: [0,1,0,2,1,0,1,3,2,1,2,1]Output:...原创 2019-07-13 14:30:44 · 135 阅读 · 0 评论 -
leetcode 128. Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4, 200, 1, 3, 2]Output: 4Explan...原创 2019-07-13 14:31:59 · 137 阅读 · 0 评论 -
leetcode 84. 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.Example:Input: [2,1,5,6,2,3]Output: 10t...原创 2019-07-13 14:34:27 · 107 阅读 · 0 评论 -
leetcode 41. First Missing Positive
Given an unsorted integer array, find the smallest missing positive 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: 1tag: a...原创 2019-07-13 14:35:57 · 110 阅读 · 0 评论 -
leetcode 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 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)).You may assume nums1 and num...原创 2019-07-13 14:38:01 · 170 阅读 · 0 评论 -
leetcode 11. Container With Most Water
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). Find two l...原创 2019-06-12 11:32:46 · 144 阅读 · 0 评论 -
Leetcode 78. Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[[3],[1],[2],...原创 2019-06-04 21:01:29 · 145 阅读 · 0 评论 -
leetcode 238. Product of Array Except Self
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]Output: [24...原创 2019-06-04 20:24:56 · 127 阅读 · 0 评论 -
leetcode 1. Two Sum
1. Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use...原创 2019-05-13 21:12:26 · 101 阅读 · 0 评论 -
leetcode 53. Maximum Subarray
Given an integer array nums, 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: 6Explanation:...原创 2019-05-20 12:15:50 · 96 阅读 · 0 评论 -
leetcode 26. Remove Duplicates from Sorted Array
Given a sorted array nums, 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 by modifyin...原创 2019-05-20 14:18:59 · 88 阅读 · 0 评论 -
leetcode 283. Move Zeroes
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.Example:Input:[0,1,0,3,12]Output:[1,3,12,0,0]tag: array, two ...原创 2019-05-12 17:00:49 · 111 阅读 · 0 评论 -
leetcode 169. Majority Element
Majority ElementGiven 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 maj...原创 2019-05-12 21:27:12 · 106 阅读 · 0 评论 -
Leectode 88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively.You may assume that n...原创 2019-05-31 23:47:01 · 147 阅读 · 0 评论 -
Leetcode 287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi...原创 2019-06-09 16:58:26 · 208 阅读 · 0 评论 -
leetcode 48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix dire...原创 2019-06-09 17:09:43 · 109 阅读 · 0 评论 -
leetcode 62. Unique Paths
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 bot...原创 2019-06-09 17:13:27 · 123 阅读 · 0 评论 -
Leetcode 189. Rotate Array
Given an array, rotate the array to the right by k steps, where k is 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: [7,1,2,...原创 2019-06-03 17:22:57 · 125 阅读 · 0 评论 -
leetcode 79. Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically ne...原创 2019-06-15 16:04:11 · 126 阅读 · 0 评论 -
leetcode 73. 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.Example 1:Input:[[1,1,1],[1,0,1],[1,1,1]]Output:[[1,0,1],[0,0,0],[1,0,1]]Example 2:Input:[...原创 2019-06-15 16:26:20 · 113 阅读 · 0 评论 -
leetcode 162. Find Peak Element
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 peaks, i...原创 2019-06-15 17:07:50 · 124 阅读 · 0 评论 -
Leetcode 289. Game of Life
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 m by n ...原创 2019-06-10 14:57:27 · 110 阅读 · 0 评论 -
Leetcode array Top Interview Questions 32道题总结
本篇文章是对leetcode array和Top Interview Questions标签下32道array类型题目的总结leetcode 283. Move Zeroes此题属于数组交换型,交换数组中元素的位置以满足某种条件解:交换数组位置,一般使用两个指针的办法,已到达O(1) space 的效果并且此题有个特殊之处,题目中将数组中的元素分为0项和非0项,也可分为数组分类型,数组分类...原创 2019-07-13 17:49:51 · 246 阅读 · 0 评论