Reverse Words in a String


  • 0
    Z

    String[] strArray = s.split(" ");
    StringBuffer stringBuffer = new StringBuffer();
    List<String> stringBufferList = new ArrayList<String>();
    for (int i=strArray.length;i>0;i--)
    {
    stringBuffer.append(strArray[i-1]+" ");
    }
    return stringBuffer.toString();


Log in to reply
 

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