Simple Solution in python


  • 0
    A

    class Solution(object):
    def reverseWords(self, s):
    """
    :type s: str
    :rtype: str
    """
    res = ""
    l = s.split()
    for i in xrange(len(l)-1,-1,-1):
    if l[i] != " ":
    res += l[i] + " "
    return res.strip()


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.