试题地址:https://leetcode-cn.com/problems/reverse-words-in-a-string/
试题思路:
go自带strings.Fields()函数,可以剔除多余空格
试题代码:
func reverseWords(s string) string { strList := strings.Fields(s) if len(strList) == 0 { return "" } reverseS := "" for i := len(strList) - 1; i > 0; i-- { reverseS += strList[i] + " " } reverseS += strList[0] return reverseS }
原文地址:https://www.cnblogs.com/ybf-yyj/p/12673341.html
时间: 2024-10-07 15:39:37