Skip to content

Files

Latest commit

1004f5b · Dec 8, 2024

History

History
27 lines (22 loc) · 667 Bytes

Question_3379.md

File metadata and controls

27 lines (22 loc) · 667 Bytes

LeetCode Records - Question 3379 Transformed Array

Attempt 1: Calculate the corresponding indices

class Solution {
    public int[] constructTransformedArray(int[] nums) {
        int[] ans = new int[nums.length];

        for (int i = 0; i < nums.length; i++) {
            int index = i + nums[i] % nums.length;
            if (index >= nums.length) {
                index %= nums.length;
            } else if (index < 0) {
                index += nums.length;
            }

            ans[i] = nums[index];
        }

        return ans;
    }
}
  • Runtime: 1 ms (Beats: 100.00%)
  • Memory: 44.72 MB (Beats: 100.00%)