classSolution(object):defreverseWords(self,s): self.reverse_part(s, 0, len(s) -1) p =0for index inrange(1, len(s)):if s[index]==' ': self.reverse_part(s, p, index -1) p = index +1 self.reverse_part(s, p, len(s) -1)defreverse_part(self,s,left,right):while left < right: s[left], s[right]= s[right], s[left] left +=1 right -=1