add: 220125
This commit is contained in:
parent
63a2679a21
commit
80dbc94aea
|
|
@ -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 {
|
class Solution {
|
||||||
public:
|
public:
|
||||||
inline static constexpr int numberOfMatches(int n) {
|
inline static constexpr int numberOfMatches(int n) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<int>& 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;
|
||||||
|
}
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2201)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2201 220125-CN.cpp)
|
ADD_EXECUTABLE(2201 220125.cpp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue