diff --git a/2201/220125-CN.cpp b/2201/220125-CN.cpp index 4df90fa..e51cb48 100644 --- a/2201/220125-CN.cpp +++ b/2201/220125-CN.cpp @@ -21,6 +21,14 @@ public: } }; +/** + * 1688. Count of Matches in Tournament + * You are given an integer n, the number of teams in a tournament that has strange rules: + * If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round. + * If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round. + * Return the number of matches played in the tournament until a winner is decided. + */ + class Solution { public: inline static constexpr int numberOfMatches(int n) { diff --git a/2201/220125.cpp b/2201/220125.cpp new file mode 100644 index 0000000..f9abf72 --- /dev/null +++ b/2201/220125.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +/** + * 941. Valid Mountain Array + * Given an array of integers arr, return true if and only if it is a valid mountain array. + * Recall that arr is a mountain array if and only if: + * - arr.length >= 3 + * - There exists some i with 0 < i < arr.length - 1 such that: + * - arr[0] < arr[1] < ... < arr[i - 1] < arr[i] + * - arr[i] > arr[i + 1] > ... > arr[arr.length - 1] + */ + +class Solution { +public: + static bool validMountainArray(const std::vector& arr) { + return std::max_element(arr.begin(), arr.end()) != arr.end() - 1 && std::max_element(arr.begin(), arr.end()) != arr.begin() && std::adjacent_find(arr.begin(), std::max_element(arr.begin(), arr.end()), std::greater_equal<>()) == std::max_element(arr.begin(), arr.end()) && std::adjacent_find(std::max_element(arr.begin(), arr.end()), arr.end(), std::less_equal<>()) == arr.end(); + } +}; + +int main() { + std::printf("%s\n", Solution::validMountainArray({0, 3, 2, 1}) ? "true" : "false"); + return 0; +} diff --git a/2201/CMakeLists.txt b/2201/CMakeLists.txt index cacd355..54f87c2 100644 --- a/2201/CMakeLists.txt +++ b/2201/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2201) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2201 220125-CN.cpp) +ADD_EXECUTABLE(2201 220125.cpp)