[Java] Solutions - 9 lines


  • 0
    C

    public class Solution {
    public String reverseWords(String s) {
    String rst = "";
    String unitString = "";
    for (int i = 0; i < s.length(); i++) {
    if (s.charAt(i) == ' ') {
    rst += unitString + ' ';
    unitString = "";
    i++;
    }
    unitString = s.charAt(i) + unitString;
    }
    return rst + unitString;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.