Leetcode 1449 Solution

This article provides solution to leetcode question 1449 (print-words-vertically)

https://leetcode.com/problems/print-words-vertically

Solution

class Solution:
    def printVertically(self, s: str) -> List[str]:
        i = 0

        tokens = s.split(" ")

        ans = []
        while True:
            v = ""

            for token in tokens:
                if i < len(token):
                    v += token[i]
                else:
                    v += " "

            v = v.rstrip(" ")

            if not v:
                break

            ans.append(v)

            i += 1

        return ans