All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0001_0100.s0006_zigzag_conversion.solution.ts Maven / Gradle / Ivy

There is a newer version: 1.8
Show newest version
// #Medium #String #2023_08_26_Time_64_ms_(95.38%)_Space_47.3_MB_(64.49%)

function convert(s: string, numRows: number): string {
    if (numRows < 2) {
        return s
    }
    const width = numRows * 2 - 2
    let result: string = ''
    let i
    let j
    for (let row = 0; row < numRows; row++) {
        i = row
        j = width - 2 * row
        while (i < s.length) {
            if (j > 0) {
                result += s[i]
            }
            i += j
            j = width - j
        }
    }
    return result
}

export { convert }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy