Skip to content

Commit 9449866

Browse files
authored
Create 2780. Minimum Index of a Valid Split (#753)
2 parents 003643f + 3bfd763 commit 9449866

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2780. Minimum Index of a Valid Split

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
struct Solution {
2+
int minimumIndex(vector<int>& nums) {
3+
int dom=1;
4+
uint dom_count=1;
5+
for (auto& i:nums) { // find dom
6+
if (dom_count==0) { ++dom_count; dom = i; }
7+
else dom_count += i==dom ? 1 : -1;
8+
}
9+
dom_count=0; // re-use as proper count
10+
for (auto& i:nums) if (i==dom) ++dom_count;
11+
uint doms=0;
12+
// cout << dom << endl;
13+
auto it=nums.begin();
14+
uint n=nums.size();
15+
for (uint i=1, j=n-1; i<=n; ++i, --j, ++it) {
16+
if (*it==dom) { ++doms; --dom_count; }
17+
// cout << doms << " " << dom_count << endl;
18+
if (doms*2>i and dom_count*2>j) return i-1;
19+
}
20+
return -1;
21+
}
22+
};

0 commit comments

Comments
 (0)