码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode1324

时间:2020-01-19 22:11:50      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:并且   str   长度   elf   def   ica   split   pre   cal   

 1 class Solution:
 2     def printVertically(self, s: str) -> List[str]:
 3         words = s.split( )
 4         matrix = []
 5         maxlen = 0
 6         for w in words:
 7             maxlen = max(maxlen,len(w))
 8         for word in words:
 9             matrix.append(word +   * (maxlen - len(word)))
10         result = []
11         for j in range(maxlen):
12             temp = ‘‘
13             for i in range(len(words)):
14                 temp += matrix[i][j]
15             result.append(temp.rstrip())
16         return result

先结算出最长的单词的长度,然后组成二维数组,按照先列后行的方式遍历,并且对每一个新组成的单词进行右边去空格处理。

leetcode1324

标签:并且   str   长度   elf   def   ica   split   pre   cal   

原文地址:https://www.cnblogs.com/asenyang/p/12215565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!