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

#include <leetcode.h>

静态 Public 成员函数

static vector< int > maxScoreIndices (vector< int > &nums)
 

详细描述

在文件 leetcode.h810 行定义.

成员函数说明

◆ maxScoreIndices()

vector< int > leetcode::all_divisions_with_the_highest_score_of_a_binary_array::Solution::maxScoreIndices ( vector< int > &  nums)
static

在文件 leetcode.cpp1944 行定义.

1944 {
1945 const auto n = nums.size();
1946 auto left_0_count = vector<int>();
1947 auto right_1_count = vector<int>();
1948 left_0_count.push_back(0);
1949 right_1_count.push_back(0);
1950 int count = 0;
1951 for(int i = 0; i < n; i++) {
1952 if(nums[i] == 0) {
1953 count++;
1954 }
1955 left_0_count.push_back(count);
1956 }
1957 count = 0;
1958 for(int i = n - 1; i >= 0; i--) {
1959 if(nums[i] == 1) {
1960 count++;
1961 }
1962 right_1_count.push_back(count);
1963 }
1964 right_1_count = vector(right_1_count.rbegin(), right_1_count.rend());
1965 int maximum = 0;
1966 for(int i = 0; i <= n; i++) {
1967 maximum = max(maximum, left_0_count[i] + right_1_count[i]);
1968 }
1969 auto ans = vector<int>();
1970 for(int i = 0; i <= n; i++) {
1971 if(maximum == left_0_count[i] + right_1_count[i]) {
1972 ans.push_back(i);
1973 }
1974 }
1975 return ans;
1976 }

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