You get a List of integers nums and a number n. Return a List with the first n numbers of nums.
Keep them in the same order. When n is 0, return an empty List.
Example 1:
Input: nums = [3, 8, 1, 9, 4], n = 3 Output: [3, 8, 1] Explanation: The first 3 numbers are 3, 8 and 1. The 9 and the 4 are left out.
Example 2:
Input: nums = [5, 6, 7], n = 0 Output: [] Explanation: No numbers are taken, so the result is empty.
Example 3:
Input: nums = [2, 4], n = 2 Output: [2, 4] Explanation: n is the length of nums, so every number is kept.
Constraints:
numshas 1 to 10 numbers.- Every number is an integer from -1000 to 1000.
nis from 0 to the length ofnums.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
