Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
best-time-to-buy-and-sell-stock.cpp 429 Bytes
Copy Edit Raw Blame History
// Time: O(n)
// Space: O(1)
class Solution {
public:
int maxProfit(vector<int> &prices) {
if (prices.empty()) {
return 0;
}
int hold1 = numeric_limits<int>::min();
int release1 = numeric_limits<int>::min();
for (const auto& p : prices) {
hold1 = max(hold1, -p);
release1 = max(release1, hold1 + p);
}
return release1;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search