problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::minimum_swaps_to_group_all_1s_together::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int minSwaps (vector< int > &data)
 

详细描述

在文件 leetcode.h3412 行定义.

成员函数说明

◆ minSwaps()

int leetcode::minimum_swaps_to_group_all_1s_together::Solution::minSwaps ( vector< int > &  data)
static

在文件 leetcode.cpp9555 行定义.

9555 {
9556 auto one_count = vector(data.size(), 0);
9557 int cnt1 = 0;
9558 for(int i = 0; i < one_count.size(); i++) {
9559 one_count[i] = cnt1 + data[i];
9560 cnt1 = one_count[i];
9561 }
9562 if(cnt1 == 0) {
9563 return 0;
9564 }
9565 int ans = cnt1 - one_count[cnt1 - 1];
9566 for(int i = 0; i + cnt1 < one_count.size(); i++) {
9567 ans = min(ans, cnt1 - (one_count[i + cnt1] - one_count[i]));
9568 }
9569 return ans;
9570 }

被这些函数引用 leetcode::minimum_swaps_to_group_all_1s_together::TEST().


该类的文档由以下文件生成: