186. Reverse Words in a String II Posted on 2020-05-24 | Edited on 2021-01-22 | Views: https://leetcode.com/problems/reverse-words-in-a-string-ii/ 1234567891011121314151617181920212223class Solution { private void reverse(char[] s,int l,int r){ while(l<r){ char tmp=s[r]; s[r--]=s[l]; s[l++]=tmp; // l++; // r--; } } public void reverseWords(char[] s) { if(s==null||s.length==0) return; int l=0,r=s.length-1; reverse(s,l,r); int j=0; for(int i=0;i<s.length;i=j+1){ j=i; while(j<s.length&&s[j]!=' ') j++; reverse(s,i,j-1); } }}