diff options
Diffstat (limited to 'build_arr_permutation.py')
-rw-r--r-- | build_arr_permutation.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/build_arr_permutation.py b/build_arr_permutation.py new file mode 100644 index 0000000..3b3baa7 --- /dev/null +++ b/build_arr_permutation.py @@ -0,0 +1,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])) |