原题地址:https://oj.leetcode.com/problems/reverse-words-in-a-string/

题意:

Given an input string, reverse the string word by word.

For example,
Given s = "the sky is blue",
return "blue is sky the".

解题思路:这题很能体现python处理字符串的强大功能。

代码:

class Solution:
    # @param s, a string
    # @return a string
    def reverseWords(self, s):
        return " ".join(s.split()[::-1])

 

相关文章:

  • 2021-09-10
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2021-10-29
  • 2022-01-14
猜你喜欢
  • 2022-01-27
  • 2021-08-21
  • 2021-12-04
  • 2022-02-11
  • 2021-10-01
  • 2021-10-29
  • 2022-02-22
相关资源
相似解决方案