Friday, November 3, 2017

557. Reverse Words in a String III

class Solution:
    def reverseWords(self, s):
        """
        :type s: str
        :rtype: str
        """
        new_list = []
        new_list = s.split()
        new_string=""
        for i in range(0,len(new_list)):
            new_list[i] = new_list[i][::-1]
            new_string = " ".join(new_list)
        return new_string

No comments:

Post a Comment