Skip to content

Commit d421171

Browse files
[LEET-3379] add 3379
1 parent 13c62b7 commit d421171

File tree

3 files changed

+61
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+61
-0
lines changed

paginated_contents/algorithms/4th_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
33
| 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy |
44
| 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy |
5+
| 3379 | [Transformed Array](https://leetcode.com/problems/transformed-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3379.java) | | Easy |
56
| 3375 | [Minimum Operations to Make Array Values Equal to K](https://leetcode.com/problems/minimum-operations-to-make-array-values-equal-to-k/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3375.java) | | Easy |
67
| 3370 | [Smallest Number With All Set Bits](https://leetcode.com/problems/smallest-number-with-all-set-bits/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3370.java) | | Easy |
78
| 3364 | [Minimum Positive Sum Subarray](https://leetcode.com/problems/minimum-positive-sum-subarray/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3364.java) | | Easy |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3379 {
4+
public static class Solution1 {
5+
public int[] constructTransformedArray(int[] nums) {
6+
int[] result = new int[nums.length];
7+
int len = nums.length;
8+
for (int i = 0; i < len; i++) {
9+
if (nums[i] > 0) {
10+
int moves = nums[i] % len;
11+
result[i] = nums[(i + moves) % len];
12+
} else if (nums[i] < 0) {
13+
if (i + nums[i] >= 0) {
14+
result[i] = nums[i + nums[i]];
15+
} else {
16+
int moves = Math.abs(nums[i]) % len;
17+
result[i] = nums[(len + (i - moves)) % len];
18+
}
19+
} else {
20+
result[i] = nums[i];
21+
}
22+
}
23+
return result;
24+
}
25+
}
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4+
5+
import com.fishercoder.solutions.fourththousand._3379;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class _3379Test {
10+
private _3379.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _3379.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertArrayEquals(
20+
new int[] {1, 1, 1, 3},
21+
solution1.constructTransformedArray(new int[] {3, -2, 1, 1}));
22+
}
23+
24+
@Test
25+
public void test2() {
26+
assertArrayEquals(
27+
new int[] {-1, -1, 4}, solution1.constructTransformedArray(new int[] {-1, 4, -1}));
28+
}
29+
30+
@Test
31+
public void test3() {
32+
assertArrayEquals(new int[] {-10}, solution1.constructTransformedArray(new int[] {-10}));
33+
}
34+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy