Given a collection of integers that might contain duplicates, nums\, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
1 | Input: [1,2,2] |
Given a collection of integers that might contain duplicates, nums\, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
1 | Input: [1,2,2] |
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
1 | Input: nums = [1,2,3] |
Given 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).
Example 1:
1 | Input: [3, 2, 1] |
Example 2:
1 | Input: [1, 2] |
Example 3:
1 | Input: [2, 2, 3, 1] |
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:
1 | Input: [0,1,0,3,12] |
Note:
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n
, find the one that is missing from the array.
Example 1:
1 | Input: [3,0,1] |
Example 2:
1 | Input: [9,6,4,2,3,5,7,0,1] |
Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Example 1:
1 | Input: [1,2,3,1] |
Example 2:
1 | Input: [1,2,3,4] |
Example 3:
1 | Input: [1,1,1,3,3,4,3,2,4,2] |
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
Example 1:
1 | Input: nums = [1,2,3,1], k = 3 |
Example 2:
1 | Input: nums = [1,0,1,1], k = 1 |
Example 3:
1 | Input: nums = [1,2,3,1,2,3], k = 2 |
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, in that case return the index to any one of the peaks is fine.
You may imagine that nums[-1] = nums[n] = -∞
.
Example 1:
1 | Input: nums = [1,2,3,1] |
Example 2:
1 | Input: nums = [1,2,1,3,5,6,4] |
Follow up: Your solution should be in logarithmic complexity.
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]
).
Find the minimum element.
You may assume no duplicate exists in the array.
Example 1:
1 | Input: [3,4,5,1,2] |
Example 2:
1 | Input: [4,5,6,7,0,1,2] |
Given an array, rotate the array to the right by k steps, where k is non-negative.
Follow up:
Example 1:
1 | Input: nums = [1,2,3,4,5,6,7], k = 3 |
Example 2:
1 | Input: nums = [-1,-100,3,99], k = 2 |
Constraints:
1 <= nums.length <= 2 * 10^4
nums[i]
fits in a 32 bit-signed integer.k >= 0