golang solution


  • 0
    C
    func reverseString(s string) string {
    	if len(s) == 1 {
    		return s
    	}
    
    	return string(s[len(s) - 1]) + reverseString(string(s[:len(s) - 1]))
    }
    
    func reverseWords(s string) string {
    	words := strings.Fields(s)
    
    	for i, word := range words {
    		reverse := reverseString(word)
    		words[i] = reverse
    	}
    
    	return strings.Join(words, " ")
    }
    

Log in to reply
 

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