![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数组
文章平均质量分 79
_xiaoyuer
世界一定有光
展开
-
LeetCode - 485 - Max Consecutive Ones
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 consecutiv原创 2017-04-25 21:34:29 · 237 阅读 · 0 评论 -
LeetCode - 414/215/374 Kth Largest Element in an Array
414. Third Maximum NumberGiven a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n原创 2017-08-01 14:54:10 · 172 阅读 · 0 评论 -
LeetCode - 54/59 - Spiral Matrix(旋转打印数组)
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 ]]原创 2017-08-08 18:20:20 · 593 阅读 · 0 评论 -
LeetCode - 75 - 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原创 2017-08-08 18:20:44 · 157 阅读 · 0 评论 -
LeetCode - 150 - Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",原创 2017-08-09 18:20:45 · 187 阅读 · 0 评论 -
leetCode - 162 - 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原创 2017-08-09 18:38:23 · 177 阅读 · 0 评论 -
LeetCode - 179 - Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2017-08-09 18:55:04 · 184 阅读 · 0 评论 -
LeetCode - 238 - Product of Array Except Self
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原创 2017-08-10 10:03:59 · 157 阅读 · 0 评论 -
LeetCode - 227 - Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should原创 2017-08-10 15:06:56 · 197 阅读 · 0 评论 -
LeetCode - 33/81/153/154 - 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 foun原创 2017-07-26 18:37:42 · 190 阅读 · 0 评论 -
LeetCode - 646 - Maximum Length of Pair Chain
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b . Chain原创 2017-08-03 22:46:20 · 565 阅读 · 0 评论 -
LeetCode - 38 - Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read原创 2017-08-04 14:29:17 · 248 阅读 · 0 评论 -
LeetCode - 31 - Next 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原创 2017-08-04 14:29:27 · 156 阅读 · 0 评论 -
LeetCode - 378 - Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not原创 2017-08-11 18:56:10 · 205 阅读 · 0 评论 -
数组中的逆序对
题目描述在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数P。并将P对1000000007取模的结果输出。 即输出P%1000000007输入描述:题目保证输入的数组中没有的相同的数字数据范围: 对于%50的数据,size 对于%75的数据,size 对于%100的数据,size示例1输入原创 2017-08-07 17:13:44 · 166 阅读 · 0 评论 -
LeetCode - 74/240 - Search a 2D Matrix
74. Search a 2D MatrixWrite 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 r原创 2017-08-06 22:06:55 · 203 阅读 · 0 评论 -
LeetCode - 349/350 - Intersection of Two Arrays
349. Intersection of Two ArraysGiven two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each eleme原创 2017-08-06 22:07:10 · 173 阅读 · 0 评论 -
LeetCode - 34/278/35 - 二分查找
34. Search for a RangeGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the o原创 2017-07-19 17:53:17 · 193 阅读 · 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原创 2017-07-22 13:13:05 · 249 阅读 · 0 评论 -
LeetCode - 532 - K-diff Pairs in an Array
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers原创 2017-04-25 22:57:57 · 230 阅读 · 0 评论 -
LeetCode - 448 - Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-07-11 11:13:54 · 163 阅读 · 0 评论 -
LeetCode - 442 - Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without ex原创 2017-07-11 11:05:03 · 148 阅读 · 0 评论 -
LeetCode - 53 - Maximum Subarray
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原创 2017-07-11 11:32:56 · 145 阅读 · 0 评论 -
LeetCode - 16 - 3Sum Closest
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原创 2017-07-12 09:33:38 · 167 阅读 · 0 评论 -
LeetCode - 18 - 4Sum
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: The solution s原创 2017-07-12 09:33:52 · 130 阅读 · 0 评论 -
LeetCode - 454 - 4Sum II
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same l原创 2017-07-12 09:34:07 · 180 阅读 · 0 评论 -
LeetCode - 15 - 3Sum(内有two sum)
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: The solution set must not contain原创 2017-07-12 09:33:23 · 157 阅读 · 0 评论 -
LeetCode - 137 - Single Number II
Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could yo原创 2017-07-13 10:09:00 · 158 阅读 · 0 评论 -
LeetCode - 260 - Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given原创 2017-07-13 10:12:45 · 187 阅读 · 0 评论 -
LeetCode - 389 - Find the Difference
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was原创 2017-07-13 10:21:25 · 195 阅读 · 0 评论 -
LeetCode - 263/264/313 - Ugly Number
263. Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example,6, 8are ugly while14...原创 2017-07-14 09:58:40 · 185 阅读 · 0 评论 -
LeetCode - 136 - Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2017-07-12 09:34:21 · 261 阅读 · 3 评论 -
LeetCode - 599 - Minimum Index Sum of Two Lists
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help them find out their common interest with the原创 2017-07-20 16:42:06 · 182 阅读 · 0 评论 -
LeetCode - 66/67 - 两数相加加法模拟
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits a原创 2017-07-18 09:52:03 · 227 阅读 · 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.我的做法是开两个vector存一下每一行或者每一列的状态,空间复杂度是O(n)。评论区的做法是直接把状态存在第一行和第一列,然后扫描的时候判断行和列的开头就可以知道是否这个值需要变为0,空间复杂原创 2017-07-22 13:12:54 · 196 阅读 · 0 评论 -
LeetCode - 4 - Median of Two Sorted Arrays(两排序数组找第k大)
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)).Example 1:nums1 =原创 2017-08-07 10:54:10 · 192 阅读 · 0 评论