Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created October 23, 2017 18:14
Show Gist options
  • Save cixuuz/50c334edfa4c97ca92a1e8c53f09034f to your computer and use it in GitHub Desktop.
Save cixuuz/50c334edfa4c97ca92a1e8c53f09034f to your computer and use it in GitHub Desktop.
[186. Reverse Words in a String II] #leetcode
class Solution(object):
def reverseWords(self, s):
"""
:type str: List[str]
:rtype: void Do not return anything, modify str in-place instead.
"""
s.reverse()
index = 0
for i in range(len(s)):
if s[i] == " ":
s[index: i] = reversed(s[index: i])
index = i + 1
s[index: ] = reversed(s[index: ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment