Golang - 不用for迴圈,利用递迴反转字串

as title

这是之前去面试的考题
想了很久,不过感觉不是最佳解
做个纪录
期待有大神看到可以提供更好的解法XD

func main() {s := "ABCDEFG"t := len(s) - 1tar1 := stringReverseRecursion1(s, t)log.Println(tar1)}func stringReverseRecursion1(temp string, times int) string {if times < 0 {return temp[len(temp)/2:]}temp += string(temp[times])times--return stringReverseRecursion1(temp, times)}

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章