blob: 3b3baa7676bf19fc1d1d59a35edde29ef7c1efc4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# 1920. Build Array from Permutation
"""
given a 0-based permutation 'nums', build an array 'ans' of the same length
where 'ans[i] = nums[nums[i]]' for each '0 <= i < nums.len' and return it. a
0-based permutation 'nums' is an array of distinct integers from 0 to
'nums.len - 1'.
"""
class Solution(object):
def buildArray(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
return [nums[i] for i in nums]
if __name__ == "__main__":
obj = Solution()
print(obj.buildArray(nums=[0, 2, 1, 5, 3, 4]))
print(obj.buildArray(nums=[5, 0, 1, 2, 3, 4]))
|