Solution in JAVA>
class Solution { public int[] buildArray(int[] nums) { int n = nums.length; for(int i=0;i<n;i++){ nums[i]=n*(nums[nums[i]]%n)+nums[i]; } for(int i=0;i<n;i++){ nums[i]=nums[i]/n; } return nums; } }
second Approach>
{ int n = nums.length; int[] ans = new int[n]; for(int i=0; i<nums.length;i++){ ans[i]= nums[nums[i]]; } return nums; }
Hey @rishavmehra, Your Second Approach is perfect in java.
But instead of return nums - > return ans will come.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Solution in JAVA>
second Approach>
Hey @rishavmehra, Your Second Approach is perfect in java.
But instead of return nums - > return ans will come.