The title

Give you a permutation nums starting at 0 (subscripts also starting at 0). Construct ans of the same length, where ans[I] = nums[nums[I]] for each I (0 <= I < nums.length). Returns the constructed array ANS.

The permutation nums from 0 is an array of different integers from 0 to nums. length-1 (0 and nums. length-1 are included).

 

Example 1: input: nums = [0,2,1,5,3,4] output: [0,1,2,4,5,3]  ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]] = [nums[0], nums[2], Nums nums [1], [5], nums [3], nums =,1,2,4,5,3 [0] [4]] example 2: input: nums =,0,1,2,3,4 [5] output:,5,0,1,2,3 [4] : array ans build is as follows:  ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]] = [nums[5], nums[0], Nums nums [1], [2], nums [3], nums =,5,0,1,2,3 [4] [4]]Copy the code

Tip:

1 <= nums.length <= 1000 0 <= nums[I] < nums.length The elements in nums are different

Their thinking

class Solution: def buildArray(self, nums: List[int]) -> List[int]: res = [] for i in nums: res.append(nums[i]) return res if __name__ == '__main__': Nums = [0,2,1,5,3,4] result = Solution(). Print (result)Copy the code