Explanation: Your reversed string should not contain leading or trailing spaces. String words[]=s.trim().split("\\s+"); // remove the leading and trailing spaces and "\\s+" remove multiple i.e more ...
Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words ...