- 双指针
function maxDepthAfterSplit(seq: string): number[] {
let aDepth: number = 0,
bDepth: number = 0;
const results: number[] = [];
for (const ch of seq) {
if (ch === '(') {
if (aDepth <= bDepth) {
++aDepth;
results.push(0);
} else {
++bDepth;
results.push(1);
}
} else {
if (aDepth <= bDepth) {
--bDepth;
results.push(1);
} else {
--aDepth;
results.push(0);
}
}
}
return results;
};