Skip to content

Commit 84c1b19

Browse files
authored
Add LC 1646 java solution (#142)
1 parent 5e6deaf commit 84c1b19

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)