From 696bf5a93e490ccc5b2067b17c686872ce506a8a Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Tue, 1 Feb 2022 21:40:47 +0800 Subject: [PATCH] add: 220201 --- 2202/220201.cpp | 19 +++++++++++++++++++ 2202/CMakeLists.txt | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 2202/220201.cpp diff --git a/2202/220201.cpp b/2202/220201.cpp new file mode 100644 index 0000000..5b2a657 --- /dev/null +++ b/2202/220201.cpp @@ -0,0 +1,19 @@ +#include +#include + +class Solution { +public: + static int maxProfit(const std::vector& prices) { + int toBuy = 0x7FFFFFFF, ret = 0; + for (int price : prices) { + ret = std::max(price - toBuy, ret); + toBuy = std::min(price, toBuy); + } + return ret; + } +}; + +int main() { + std::printf("%d\n", Solution::maxProfit({7,6,4,3,1})); + return 0; +} diff --git a/2202/CMakeLists.txt b/2202/CMakeLists.txt index 8de4ac6..75b30db 100644 --- a/2202/CMakeLists.txt +++ b/2202/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2202) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2202 220201-CN.cpp) +ADD_EXECUTABLE(2202 220201.cpp)