Explanation

572.Copy an Array

Easy
Given an array nums, return a new array containing the same values in the same order. Copying exposes an important detail: in most languages an array variable holds a referenceReferenceA value that points to where an object lives in memory. Copying a reference gives a second name for the same object, not a new object. to the data. Writing copy = nums creates a second name for the same array, not a new one — a true copyCopy (Shallow Copy)A new array that holds the same values in its own memory, so changing one does not affect the other. needs its own memory filled with the values.

Example 1:

Input: nums = [5,1,8]

Output: [5,1,8]

Example 2:

Input: nums = [0]

Output: [0]

+ 3 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ nums.length ≤ 1000
  • ●-1000000 ≤ nums[i] ≤ 1000000

nums =

[5, 1, 8]