Skip to content

Commit 2c39cc4

Browse files
add 1968
1 parent 24a6bbb commit 2c39cc4

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1968|[Array With Elements Not Equal to Average of Neighbors](https://leetcode.com/problems/array-with-elements-not-equal-to-average-of-neighbors/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1968.java) ||Medium||
1112
|1967|[Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1967.java) ||Easy||
1213
|1961|[Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1961.java) ||Easy||
1314
|1957|[Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1957.java) ||Easy|String|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _1968 {
6+
public static class Solution1 {
7+
public int[] rearrangeArray(int[] nums) {
8+
Arrays.sort(nums);
9+
int[] result = new int[nums.length];
10+
int j = 1;
11+
for (int i = 0; i < nums.length / 2; i++) {
12+
result[j] = nums[i];
13+
j += 2;
14+
}
15+
j = 0;
16+
for (int i = nums.length / 2; i < nums.length; i++) {
17+
result[j] = nums[i];
18+
j += 2;
19+
}
20+
return result;
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions._1968;
5+
import org.junit.BeforeClass;
6+
import org.junit.Test;
7+
8+
public class _1968Test {
9+
private static _1968.Solution1 solution1;
10+
11+
@BeforeClass
12+
public static void setup() {
13+
solution1 = new _1968.Solution1();
14+
}
15+
16+
@Test
17+
public void test1() {
18+
CommonUtils.printArray(solution1.rearrangeArray(new int[]{1, 2, 3, 4, 5}));
19+
}
20+
21+
}

0 commit comments

Comments
 (0)