and rotate array is a way to turn the whole turn around and then each word is turned around alone
1 Public voidReversewords (Char[] s) {2 if(S.length = = 0) {3 return;4 }5 intLen =s.length;6Reverse (s, 0, len-1);7 intWalker = Findnextword (s, 0);8 intRunner =Findendofword (S, Walker);9 while(Runner <=Len) {TenReverse (S, Walker, runner-1); OneWalker =Findnextword (S, runner); A if(Walker >=Len) { - return; - } theRunner =Findendofword (S, Walker); - } - } - + Private intFindnextword (Char[] s,intstart) { - intindex =start; + while(Index < s.length && S[index] = = ") { Aindex++; at } - returnindex; - } - - Private intFindendofword (Char[] s,intstart) { - intindex =start; in while(Index < s.length && S[index]! = ") { -index++; to } + returnindex; - } the * Private voidReverseChar[] s,intStartintend) { $ while(End >start) {Panax Notoginseng Charx =S[start]; -S[start] =S[end]; theS[end] =x; +start++; Aend--; the } +}
186. Reverse Words in a String II