1. Description
2. Solution
**解析:**Version 1,先将字符串按空格分开,然后找到最长的子串长度,遍历长度构造结果子串,注意每个子串后面的空格要去掉。
- Version 1
class Solution:
def printVertically(self, s: str) -> List[str]:
result = []
words = s.split(' ')
n = max(list(map(len, words)))
for i in range(n):
temp = ''
for word in words:
if i < len(word):
temp = word[i]
else:
temp = ' '
result.append(temp.rstrip())
return result
Reference
- https://leetcode.com/problems/print-words-vertically/