problemscpp
A collection of my answers to algorithm problems in c++.
leetcode
minimum_deletions_to_make_array_beautiful
Solution
静态 Public 成员函数
|
所有成员列表
leetcode::minimum_deletions_to_make_array_beautiful::Solution类 参考
#include <
leetcode.h
>
静态 Public 成员函数
static int
minDeletion
(vector< int > &nums)
详细描述
在文件
leetcode.h
第
1928
行定义.
成员函数说明
◆
minDeletion()
int leetcode::minimum_deletions_to_make_array_beautiful::Solution::minDeletion
(
vector< int > &
nums
)
static
在文件
leetcode.cpp
第
5057
行定义.
5057
{
5058
vector<int> indexes;
5059
for
(
int
i = 0; i + 1 < nums.size(); i++) {
5060
if
(nums[i] == nums[i + 1]) {
5061
indexes.push_back(i);
5062
}
5063
}
5064
int
ans = 0;
5065
bool
even =
true
;
5066
for
(
const
auto
index: indexes) {
5067
if
(even && index % 2 == 0 || !even && index % 2 != 0) {
5068
ans++;
5069
even = !even;
5070
}
5071
}
5072
if
((nums.size() - ans) % 2 != 0) {
5073
ans++;
5074
}
5075
return
ans;
5076
}
该类的文档由以下文件生成:
leetcode.h
leetcode.cpp
制作者
1.9.2