From 5d284be8e4342d2b1a8fa9c903668028185c4814 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Mon, 19 Sep 2022 13:54:00 -0400 Subject: [PATCH] Create README - LeetHub --- 1920-build-array-from-permutation/README.md | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 1920-build-array-from-permutation/README.md diff --git a/1920-build-array-from-permutation/README.md b/1920-build-array-from-permutation/README.md new file mode 100644 index 0000000..50d20dc --- /dev/null +++ b/1920-build-array-from-permutation/README.md @@ -0,0 +1,35 @@ +

1920. Build Array from Permutation

Easy


Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.

+ +

A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).

+ +

 

+

Example 1:

+ +
Input: nums = [0,2,1,5,3,4]
+Output: [0,1,2,4,5,3]
+Explanation: The array ans is built as follows: 
+ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
+    = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]
+    = [0,1,2,4,5,3]
+ +

Example 2:

+ +
Input: nums = [5,0,1,2,3,4]
+Output: [4,5,0,1,2,3]
+Explanation: The array ans is built 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[1], nums[2], nums[3], nums[4]]
+    = [4,5,0,1,2,3]
+ +

 

+

Constraints:

+ + + +

 

+

Follow-up: Can you solve it without using an extra space (i.e., O(1) memory)?

+
\ No newline at end of file