Skip to content

Latest commit

 

History

History
35 lines (29 loc) · 795 Bytes

1111. 有效括号的嵌套深度.md

File metadata and controls

35 lines (29 loc) · 795 Bytes
  • 双指针
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;
};