- Published on
Leetcode 1920 - Build Array from Permutation solution
- Authors
- Name
- Imran Pollob
- Website
- @pollmix
Solution One:
class Solution {
public int[] buildArray(int[] nums) {
int[] ans = new int[nums.length];
for(int i = 0; i < nums.length; i++){
ans[i] = nums[nums[i]];
}
return ans;
}
}
class Solution:
def buildArray(self, nums: List[int]) -> List[int]:
ans = []
for i in range(len(nums)):
ans.append(nums[nums[i]])
return ans