// Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.

// The input string does not contain leading or trailing spaces and the words are always separated by a single space.

// For example,
// Given s = "the sky is blue",
// return "blue is sky the".

// Do it in-place without allocating extra space?

@@ -357,8 +357,525 @@
  space?%0A
+%0Avar reverseWords = function(str) %7B%0A    reverse(str, 0, str.length - 1);%0A    var start = 0,%0A        end = -1;%0A%0A    for( var i = 0; i %3C str.length; i++ )%7B%0A        if( str%5Bi%5D == ' ' ) %7B%0A            reverse( str, start, i-1 );%0A            start = i + 1;%0A        %7D%0A    %7D%0A    reverse( str, start, str.length - 1 );%0A%7D;%0A%0Afunction reverse(string, start, end)%7B%0A    while (start %3C end) %7B%0A        var temp = string%5Bstart%5D;%0A        string%5Bstart%5D = string%5Bend%5D;%0A        string%5Bend%5D = temp;%0A        start++;%0A        end--;%0A    %7D%0A%7D%0A

add solution