Notes

Personal notes on various topics

View on GitHub

ZigZag conversion

Problem Statement

Given a string, write it in a zigzag pattern on a given number of rows and then read the result line by line.

For example, the string "PAYPALISHIRING" written in a zigzag pattern with 3 rows looks like:

P   A   H   N
A P L S I I G
Y   I   R

Reading line by line gives: "PAHNAPLSIIGYIR".

Implement the following function:

def convert(s: str, numRows: int) -> str:

Examples

Example 1:

Example 2:

Example 3:

Constraints

Code Template

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        # Write your code here
        pass

Solutions

Back to Problem List Back to Categories