https://leetcode.com/problems/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]
呀,天亮了
Apr 05, 2020 01:17:12 AM
https://leetcode.com/problems/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]
Apr 03, 2020 01:11:04 AM
https://leetcode.com/problems/happy-number/
Write an algorithm to determine if a number is "happy".
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.
Example:
Input: 19 Output: true Explanation: 12 + 92 = 82 82 + 22 = 68 62 + 82 = 100 12 + 02 + 02 = 1
Apr 02, 2020 10:00:41 AM
https://leetcode.com/problems/largest-number-at-least-twice-of-others/
In a given integer array nums
, there is always exactly one largest element.
Find whether the largest element in the array is at least twice as much as every other number in the array.
If it is, return the index of the largest element, otherwise return -1.
Example 1:
Input: nums = [3, 6, 1, 0] Output: 1 Explanation: 6 is the largest integer, and for every other number in the array x, 6 is more than twice as big as x. The index of value 6 is 1, so we return 1.
Apr 02, 2020 09:10:49 AM
https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/
https://leetcode.com/problems/hand-of-straights
Given an array of integers nums
and a positive integer k
, find whether it's possible to divide this array into sets of k
consecutive numbers
Return True
if it's possible otherwise return False
.
Example 1:
Input: nums = [1,2,3,3,4,4,5,6], k = 4 Output: true Explanation: Array can be divided into [1,2,3,4] and [3,4,5,6].
Apr 02, 2020 06:58:08 AM
https://leetcode.com/problems/corporate-flight-bookings/
There are n
flights, and they are labeled from 1
to n
.
We have a list of flight bookings. The i
-th booking bookings[i] = [i, j, k]
means that we booked k
seats from flights labeled i
to j
inclusive.
Return an array answer
of length n
, representing the number of seats booked on each flight in order of their label.
Example 1:
Input: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5 Output: [10,55,45,25,25]
Apr 02, 2020 06:24:40 AM
https://leetcode.com/problems/check-if-n-and-its-double-exist/
Given an array arr
of integers, check if there exists two integers N
and M
such that N
is the double of M
( i.e. N = 2 * M
).
More formally check if there exists two indices i
and j
such that :
i != j
0 <= i, j < arr.length
arr[i] == 2 * arr[j]
Apr 02, 2020 06:07:17 AM
https://leetcode.com/problems/minimum-absolute-difference/
Given an array of distinct integers arr
, 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), each pair [a, b]
follows
a, b
are from arr
a < b
b - a
equals to the minimum absolute difference of any two elements in arr
Constraints:
2 <= arr.length <= 10^5
-10^6 <= arr[i] <= 10^6
Apr 02, 2020 05:41:35 AM
https://leetcode.com/problems/array-transformation/
Given an initial array arr
, every day you produce a new array using the array of the previous day.
On the i
-th day, you do the following operations on the array of day i-1
to produce the array of day i
:
After some days, the array does not change. Return that final array.
Input: arr = [1,6,3,4,3,5] Output: [1,4,4,4,4,5] Explanation: On the first day, the array is changed from [1,6,3,4,3,5] to [1,5,4,3,4,5]. On the second day, the array is changed from [1,5,4,3,4,5] to [1,4,4,4,4,5]. No more operations can be done to this array.
Apr 02, 2020 05:29:07 AM
https://leetcode.com/problems/minimum-time-visiting-all-points/
On a plane there are n
points with integer coordinates points[i] = [xi, yi]
. Your task is to find the minimum time in seconds to visit all points.
You can move according to the next rules:
Apr 02, 2020 05:19:35 AM
https://leetcode.com/problems/create-target-array-in-the-given-order/
Given two arrays of integers nums
and index
. Your task is to create target array under the following rules:
index[i]
the value nums[i]
in target array.nums
and index.
Return the target array.
It is guaranteed that the insertion operations will be valid.
Example 1:
Input: nums = [0,1,2,3,4], index = [0,1,2,2,1] Output: [0,4,1,3,2] Explanation: nums index target 0 0 [0] 1 1 [0,1] 2 2 [0,1,2] 3 2 [0,1,3,2] 4 1 [0,4,1,3,2]