classSolution{ public String reverseWords(String s){ if (s == null) return""; if (s.length() < 2) return s; int i = 0; int j = 0; int id = 0; char[] seq = s.toCharArray(); while (id < s.length()){ if (seq[id] == ' '){ j = id -1; while(i < j){ char tmp = seq[i]; seq[i] = seq[j]; seq[j] = tmp; i ++; j --; } i = id + 1; } id ++; } j = id -1; while(i < j){ char tmp = seq[i]; seq[i] = seq[j]; seq[j] = tmp; i ++; j --; } String res = new String(seq); return res; } }