Skip to content

Commit 0773f9c

Browse files
add 1646
1 parent 32bd02c commit 0773f9c

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ _If you like this project, please leave me a star._ ★
1111
|1657|[Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1657.java) ||Medium|Greedy|
1212
|1656|[Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1656.java) ||Easy|Array, Design|
1313
|1652|[Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1652.java) ||Easy|Array|
14+
|1646|[Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1646.java) ||Easy|Array|
1415
|1640|[Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1640.java) ||Easy|Array, Sort|
1516
|1637|[Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/)|[Javascript](./javascript/_1637.js)| | Medium | Sort |
1617
|1636|[Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1636.java) ||Easy|Array, Sort|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1646 {
4+
public static class Solution1 {
5+
public int getMaximumGenerated(int n) {
6+
if (n == 0) {
7+
return 0;
8+
}
9+
int[] nums = new int[n + 1];
10+
nums[0] = 0;
11+
nums[1] = 1;
12+
int max = 1;
13+
for (int i = 1; i <= n / 2; i++) {
14+
nums[(i * 2)] = nums[i];
15+
max = Math.max(max, nums[i]);
16+
if ((i * 2) + 1 <= n) {
17+
nums[(i * 2) + 1] = nums[i] + nums[i + 1];
18+
max = Math.max(max, nums[(i * 2) + 1]);
19+
}
20+
}
21+
return max;
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1646;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1646Test {
10+
private static _1646.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1646.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.getMaximumGenerated(3));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(1, solution1.getMaximumGenerated(2));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)