首页 > 其他 > 详细

leetcode151

时间:2019-12-10 14:03:07      阅读:111      评论:0      收藏:0      [点我收藏+]
 1 class Solution:
 2     def reverseWords(self, s: str) -> str:
 3         s = s.strip()
 4         ary = s.split( )
 5         temp = []
 6         for string in ary:
 7             if len(string) != 0 and string != ‘‘:
 8                 temp.append(string)
 9         for i in range(len(temp)):
10             temp[i] = temp[i][::-1]#当前字符串反转
11         
12         return " ".join(temp)[::-1]#整个字符串反转

剑指Offer 58题相似,增加了对空白字符的处理。

leetcode151

原文:https://www.cnblogs.com/asenyang/p/12016030.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!