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)