[Python] Zigzag Conversion – Code Review Request (LeetCode Medium) [closed]

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I’m currently working through technical interview challenges to improve my backend development skills, and I recently completed the Zigzag Conversion problem on LeetCode. This is my solution.

    class Solution:
    def convert(self, s: str, numRows: int) -> str:
    if numRows <= 1:
    return s

    rows = ['' for _ in range(numRows)]
    current_row = 0
    going_down = False

    for char in s:
    rows[current_row] += char
    if current_row == 0 or current_row == numRows - 1:
    going_down = not going_down
    current_row += 1 if going_down else -1

    return ''.join(rows)


    I'd love any advice or feedback from the community on:

    • Improving readability and structure
    • Would you use the 'walrus' operator from python 3.8
    • Writing more scalable or optimized logic
    • Other cleaner or Pythonic approaches
    • Any best practices you’d apply to make this code more professional

    Continue reading...

Compartilhe esta Página