initial commit

This commit is contained in:
wt
2026-04-08 15:12:07 +07:00
commit 942e4e2dc1
30 changed files with 297 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
#include <cassert>
#include <iostream>
#include "maxprofit2.hpp"
int main() {
std::vector<int> prices = {7, 1, 5, 3, 6, 4};
int k = maxProfit(prices);
std::cout << "k: " << k << std::endl;
assert(k == 7);
prices = {1, 2, 3, 4, 5};
k = maxProfit(prices);
std::cout << "k: " << k << std::endl;
assert(k == 4);
prices = {7, 6, 4, 3, 1};
k = maxProfit(prices);
std::cout << "k: " << k << std::endl;
assert(k == 0);
return 0;
}
+11
View File
@@ -0,0 +1,11 @@
#include <vector>
inline int maxProfit(std::vector<int> &prices) {
int profit = 0;
for (int i = 1; i < int(prices.size()); i++) {
if (prices[i] > prices[i - 1]) {
profit += prices[i] - prices[i - 1];
}
}
return profit;
}