We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5e6deaf commit 84c1b19Copy full SHA for 84c1b19
Algorithms/Easy/1646_GetMaximumInGeneratedArray/Solution.java
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ public int getMaximumGenerated(int n) {
3
+ int[] nums = new int[n + 1];
4
+ int max = 0;
5
+
6
+ for (int i = 0; i <= n; i++) {
7
+ if (i < 2) {
8
+ nums[i] = i;
9
+ } else if (i % 2 == 0) {
10
+ nums[i] = nums[i / 2];
11
+ } else {
12
+ nums[i] = nums[(i - 1) / 2] + nums[1 + (i - 1) / 2];
13
+ }
14
15
+ max = Math.max(max, nums[i]);
16
17
18
+ return max;
19
20
+}
0 commit comments