Created
October 23, 2017 18:14
-
-
Save cixuuz/50c334edfa4c97ca92a1e8c53f09034f to your computer and use it in GitHub Desktop.
[186. Reverse Words in a String II] #leetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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