diff options
author | Jack Sangdahl <[email protected]> | 2025-05-05 21:34:05 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-05-05 21:34:05 -0600 |
commit | 60f186c6df107c7632d37fe8bde204fb9ba54b6c (patch) | |
tree | f36eec3f6214f753540f992fc72ebd0c1de55e73 /build_arr_permutation.py | |
parent | 8613fd28cfba0f76c4bf7266ba268fcbc5830a52 (diff) | |
download | leetcode-60f186c6df107c7632d37fe8bde204fb9ba54b6c.tar.gz leetcode-60f186c6df107c7632d37fe8bde204fb9ba54b6c.zip |
1920. build array from permutation
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])) |