8000 Sync LeetCode submission - Build Array from Permutation (java) · thatbeautifuldream/leetcode-sync@bc7b366 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc7b366

Browse files
Sync LeetCode submission - Build Array from Permutation (java)
1 parent 05fcf09 commit bc7b366

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

practice/problems/build_array_from_permutation/solution.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
class Solution {
22
public int[] buildArray(int[] nums) {
33
int[] res = new int[nums.length];
4-
for(int i = 0; i<nums.length; i++) {
5-
res[i] = nums[nums[i]];
4+
int i = nums.length - 1;
5+
while(i >= 0) {
6+
res[nums.length - i - 1] = nums[nums[nums.length - i - 1]];
7+
i--;
68
}
79
return res;
810
}

0 commit comments

Comments
 (0)
0