Java easy to understand


  • 0
    G

    public class Solution {
    public String reverseWords(String s) {
    String[] s1=s.split(" ");
    StringBuilder sb0=new StringBuilder();
    StringBuilder sb1=new StringBuilder();
    for(int i=0;i<s1.length;i++){
    sb1.append(sb0.append(s1[i]).reverse());
    sb0.delete(0,sb0.length());
    if(i!=s1.length-1){
    sb1.append(" ");
    }
    }
    return sb1.toString();
    }
    }


Log in to reply
 

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