Golang concise


  • 0
    A
    func reverseWords(s string) string {
    	ss := strings.Split(s, ` `)
    	for i := range ss {
    		ss[i] = func(s string) string {
    			b, l := []byte(s), len(s)
    			for lo, hi := 0, l-1; lo < hi; lo, hi = lo+1, hi-1 {
    				b[lo], b[hi] = b[hi], b[lo]
    			}
    			return string(b)
    		}(ss[i])
    	}
    	return strings.Join(ss, ` `)
    }
    

Log in to reply
 

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