我尝试使用golang来解决这个问题557. 反转字符串中的单词 III 我的代码如下:
import "fmt"
import ss "strings"
func reverseWords(s string) string {
words := ss.Split(s," ");
res := "";
for i:=0; i < len(words);i++{
curWord := ss.Split(words[i],"");
for j:=len(curWord)-1; j >= 0;j--{
res += curWord[j];
}
if(i!=len(words)-1){
res += " ";
}
}
return res;
}
func main(){
s := "Let's take LeetCode contest";
fmt.Println(reverseWords(s));
}
我的电脑上一切都正常,至少可以通过编译。
然而,当我在Leetcode上提交时,它告诉我:
Line 67: undefined: strings in strings.Trim
我在谷歌上搜索了这个错误,但没有找到相关的信息。作为一个golang的初学者,我需要帮助。感激不尽。