leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1646.cpp (419B)


0 class Solution {
1 public:
2 int getMaximumGenerated(int n) {
3 if (n == 0) return 0;
4 if (n == 1) return 1;
5 vector<int> vec(n + 1);
6 vec[0] = 0;
7 vec[1] = 1;
9 int maxi = 0;
10 for (int i = 2; i <= n; i++) {
11 vec[i] = vec[i / 2];
12 if (i % 2) vec[i] += vec[i / 2 + 1];
13 maxi = max(vec[i], maxi);
14 }
16 return maxi;
17 }
18 };