My simple but not good java solution


  • 0
    Y
    public class Solution {
        public void reverseWords(char[] s) {
           
            if(s == null || s.length == 0)
                return;
            String word = new String();
            String res = new String();
            for(int i = 0 ; i < s.length ; i++){
                if(s[i] == ' '){
                	    res = word+ " " + res ;
                    word = new String();
                }
                else{
                    word = word + s[i];
                }
            }
            res = word+ " " + res ;
            for(int i = 0 ; i < s.length ; i++){
                s[i] = res.charAt(i);
            }
        
        } 
    }
    // my code is not smart as others'. I just want share my solution. Thanks for you all.
    

Log in to reply
 

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