add: 220113-CN
This commit is contained in:
parent
1032f9464c
commit
a093e2a47b
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
static int dominantIndex(const std::vector<int>& nums) {
|
||||||
|
int a = 0, b = -1, n = nums.size();
|
||||||
|
if (n == 1)
|
||||||
|
return 0;
|
||||||
|
for (int i = 1; i < n; ++i) {
|
||||||
|
if (nums[i] > nums[a]) {
|
||||||
|
b = a;
|
||||||
|
a = i;
|
||||||
|
} else if (b < 0 || nums[i] > nums[b]) {
|
||||||
|
b = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (b < 0 || (nums[a]) < (nums[b] << 1))
|
||||||
|
return -1;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::cout << Solution::dominantIndex({1, 0});
|
||||||
|
}
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2201)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2201 220112.cpp)
|
ADD_EXECUTABLE(2201 220113-CN.cpp)
|
||||||
Loading…
Reference in New Issue