0%

• 26. Remove Duplicates from Sorted Array
• 27. Remove Element
• 88. Merge Sorted Array
• 189. Rotate Array
• 209. Minimum Size Subarray Sum
• 228. Summary Ranges
• 238. Product of Array Except Self
• 674. Longest Continuous Increasing Subsequence
• 713. Subarray Product Less Than K
• 717. 1-bit and 2-bit Characters
• 798. Smallest Rotation with Highest Score
1. 等价多米诺骨牌对的数量

### 26. Remove Duplicates from Sorted Array

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 by modifying the input array in-place with O(1) extra memory.

Example:

Given nums = [1,1,2],

Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn't matter what you leave beyond the new length.

C++

Python

### 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-place with O(1) extra memory.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

Example:

Given nums = [3,2,2,3], val = 3,

Your function should return length = 2, with the first two elements of nums being 2.

C++

Python

### 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 elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectively.

C++

Python

### 189. 旋转数组

• 尽可能想出更多的解决方案，至少有三种不同的方法可以解决这个问题。
• 要求使用空间复杂度为 O(1) 的 原地 算法。

c++代码如下

### 209. Minimum Size Subarray Sum

Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.

For example, given the array [2,3,1,2,4,3] and s = 7, the subarray [4,3] has the minimal length under the problem constraint.

C++

Java

Python

### 228. Summary Ranges

You are given a sorted unique integer array nums.

Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums.

Each range [a,b] in the list should be output as:

• "a->b" if a != b
• "a" if a == b

Example 1:

Example 2:

Example 3:

Example 4:

Example 5:

Constraints:

• 0 <= nums.length <= 20
• -231 <= nums[i] <= 231 - 1
• All the values of nums are unique.
• nums is sorted in ascending order.

### 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(n).

For example, given [1,2,3,4], return [24,12,8,6].

Follow up: Could you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)

• 给定一个数组，对于每个元素求除了该元素的其他数的乘积。要求不用除法、时间复杂度O(1)

C++

C++

Java

Python

### 674. 最长连续递增序列

• 0 <= nums.length <= 104
• -109 <= nums[i] <= 109

### 713. Subarray Product Less Than K

Your are given an array of positive integers nums.

Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less than k.

Example 1:

Note:

• 0 < nums.length <= 50000.
• 0 < nums[i] < 1000.
• 0 <= k < 10^6.

C++

C++

Java

Python

### 717. 1-bit and 2-bit Characters

We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).

Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.

Example 1:

Example 2:

Note:

• 1 <= len(bits) <= 1000.
• bits[i] is always 0 or 1.

C++

### 798. Smallest Rotation with Highest Score

Given an array A, we may rotate it by a non-negative integer K so that the array becomes A[K], A[K+1], A{K+2], ... A[A.length - 1], A[0], A[1], ..., A[K-1].  Afterward, any entries that are less than or equal to their index are worth 1 point.

For example, if we have [2, 4, 1, 3, 0], and we rotate by K = 2, it becomes [1, 3, 0, 2, 4].  This is worth 3 points because 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point].

Over all possible rotations, return the rotation index K that corresponds to the highest score we could receive.  If there are multiple answers, return the smallest such index K.

Example 1: Input: [2, 3, 1, 4, 0] Output: 3 Explanation: Scores for each K are listed below: K = 0, A = [2,3,1,4,0], score 2 K = 1, A = [3,1,4,0,2], score 3 K = 2, A = [1,4,0,2,3], score 3 K = 3, A = [4,0,2,3,1], score 4 K = 4, A = [0,2,3,1,4], score 3

So we should choose K = 3, which has the highest score.

Example 2: Input: [1, 3, 0, 2, 4] Output: 0 Explanation: A will always have 3 points no matter how it shifts. So we will choose the smallest K, which is 0.

Note:

A will have length at most 20000. A[i] will be in the range [0, A.length].

• 当我们进行循环左移的时候，原本下标为0的元素变到n - 1，因为所有元素都<=N - 1，因此肯定有分数+1

• 而我们需要做的事就是记录各个元素移动多少步之后分数-1

• k = (i - A[i] + n) % n可以算出A[i]==i的元素下标，要是移动超过k步，就说明score应该-1
• 统计各个数字的k即可
• PS: 我们并不关心一开始是多少分，只关心最后谁最大即可。因此对于每个元素不用看最开始是否能得分，就看什么时候加分什么时候减分就行了。

C++

Python

### 1128. 等价多米诺骨牌对的数量

0 <= i < j < dominoes.length 的前提下，找出满足 dominoes[i]dominoes[j] 等价的骨牌对 (i, j) 的数量。

• 1 <= dominoes.length <= 40000
• 1 <= dominoes[i][j] <= 9