
array
文章平均质量分 70
ForABiggerWorld
这个作者很懒,什么都没留下…
展开
-
735. Asteroid Collision
We are given an array asteroids of integers representing asteroids in a row.For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, ne...原创 2017-11-26 12:11:34 · 613 阅读 · 0 评论 -
901. Online Stock Span
Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock's price for the current day.The span of the stock's price today is defined as the maxi...原创 2018-09-09 11:17:48 · 390 阅读 · 0 评论 -
945. Minimum Increment to Make Array Unique
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.Return the least number of moves to make every value in A unique. Example 1:Input: [1,2,2]Output:...原创 2018-11-25 12:29:59 · 267 阅读 · 0 评论 -
950. Reveal Cards In Increasing Order
In a deck of cards, every card has a unique integer. You can order the deck in any order you want.Initially, all the cards start face down (unrevealed) in one deck.Now, you do the following steps...原创 2018-12-02 12:47:10 · 633 阅读 · 0 评论 -
969. Pancake Sorting
Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, then reverse the order of the first kelements of A. We want to perform zero or more pancake flips (d...原创 2019-01-06 12:16:17 · 412 阅读 · 0 评论 -
976. Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths.If it is impossible to form any triangle of non-zero area, return ...原创 2019-01-13 12:00:48 · 218 阅读 · 0 评论 -
1021. Best Sightseeing Pair
Given an arrayAof positive integers,A[i]represents the value of thei-th sightseeing spot, and twosightseeing spotsiandjhave distancej - ibetween them.Thescoreof a pair (i < j) of si...原创 2019-03-24 12:06:08 · 275 阅读 · 0 评论 -
1031. Maximum Sum of Two Non-Overlapping Subarrays
Given an arrayAof non-negative integers, return the maximum sum of elements in two non-overlapping (contiguous) subarrays, which have lengthsLandM. (For clarification, theL-length subarray coul...原创 2019-04-21 12:04:14 · 330 阅读 · 0 评论 -
1053. Previous Permutation With One Swap
Given an arrayAof positive integers (not necessarily distinct), return the lexicographically largest permutation that is smaller thanA, that can bemade with one swap(Aswapexchanges the position...原创 2019-05-26 12:00:04 · 272 阅读 · 0 评论 -
1144. Decrease Elements To Make Array Zigzag
Given an arraynumsof integers, amoveconsists of choosing any element anddecreasing it by 1.An arrayAis azigzag arrayif either:Every even-indexed element is greater than adjacent elements,...原创 2019-08-04 12:03:46 · 395 阅读 · 0 评论 -
1139. Largest 1-Bordered Square
Given a 2Dgridof0s and1s, return the number of elements inthe largestsquaresubgrid that has all1s on itsborder, or0if such a subgriddoesn't exist in thegrid.Example 1:Input: grid ...原创 2019-07-28 13:24:33 · 412 阅读 · 0 评论 -
1169. Invalid Transactions
A transaction ispossibly invalidif:the amount exceeds $1000, or; if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.Each transaction str...原创 2019-08-25 13:57:21 · 575 阅读 · 0 评论 -
1170. Compare Strings by Frequency of the Smallest Character
Let's define a functionf(s)over a non-empty strings, which calculates the frequency of the smallest character ins. For example,ifs = "dcce"thenf(s) = 2because the smallest character is"c"an...原创 2019-08-25 13:57:30 · 431 阅读 · 0 评论 -
853. Car Fleet
N cars are going to the same destination along a one lane road. The destination is target miles away.Each car i has a constant speed speed[i] (in miles per hour), and initial position position[i] m...原创 2018-08-17 15:09:29 · 200 阅读 · 0 评论 -
891. Sum of Subsequence Widths
Given an array of integers A, consider all non-empty subsequences of A.For any sequence S, let the width of S be the difference between the maximum and minimum element of S.Return the sum of the w...原创 2018-08-19 14:04:09 · 400 阅读 · 0 评论 -
889. Spiral Matrix III
On a 2 dimensional grid with R rows and C columns, we start at (r0, c0) facing east.Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the grid is a...原创 2018-08-13 17:10:03 · 337 阅读 · 0 评论 -
88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional ...原创 2017-11-14 19:11:06 · 208 阅读 · 0 评论 -
27. Remove Element
Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-原创 2017-11-27 21:28:30 · 274 阅读 · 0 评论 -
835. Image Overlap
Two images A and B are given, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)We translate one image however we choose (sliding it left, right,...原创 2018-05-13 12:03:58 · 1770 阅读 · 0 评论 -
45. Jump Game II
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原创 2016-11-17 19:02:11 · 351 阅读 · 0 评论 -
855. 考场就座
在考场里,一排有 N 个座位,分别编号为 0, 1, 2, ..., N-1 。当学生进入考场后,他必须坐在能够使他与离他最近的人之间的距离达到最大化的座位上。如果有多个这样的座位,他会坐在编号最小的座位上。(另外,如果考场里没有人,那么学生就坐在 0 号座位上。)返回 ExamRoom(int N) 类,它有两个公开的函数:其中,函数 ExamRoom.seat() 会返回一个 int (整型数...原创 2018-06-17 14:30:47 · 540 阅读 · 0 评论 -
850. Rectangle Area II
We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [x1, y1, x2, y2] , where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-righ...原创 2018-06-10 13:35:48 · 1878 阅读 · 0 评论 -
861. Score After Flipping Matrix
We have a two dimensional matrix A where each value is 0 or 1.A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.Afte...原创 2018-07-01 11:57:08 · 364 阅读 · 0 评论 -
862. Shortest Subarray with Sum at Least K
Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K.If there is no non-empty subarray with sum at least K, return -1. Example 1:Input: A = [1], K = 1Output: 1E...原创 2018-07-01 12:08:07 · 695 阅读 · 0 评论 -
869. Reordered Power of 2
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero.Return true if and only if we can do this in a way such th...原创 2018-07-15 11:06:35 · 621 阅读 · 0 评论 -
870. Advantage Shuffle
Given two arrays A and B of equal size, the advantage of A with respect to B is the number of indices i for which A[i] > B[i].Return any permutation of A that maximizes its advantage with respect t...原创 2018-07-15 11:08:10 · 423 阅读 · 0 评论 -
877. Stone Game
Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].The objective of the game is to en...原创 2018-07-29 11:30:48 · 469 阅读 · 0 评论 -
874. Walking Robot Simulation
A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands:-2: turn left 90 degrees -1: turn right 90 degrees 1 <= x <...原创 2018-07-22 12:19:18 · 391 阅读 · 0 评论 -
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: 4Ex...原创 2018-08-05 11:41:00 · 148 阅读 · 0 评论 -
1191. K-Concatenation Maximum Sum
Given an integer arrayarrand an integerk, modify the array by repeating itktimes.For example, ifarr= [1, 2]andk = 3then the modified array will be[1, 2, 1, 2, 1, 2].Return the maximum s...原创 2019-09-15 15:01:37 · 459 阅读 · 0 评论