From c430004a0b8b91419e43bb648b0b2c3b5a8b5db2 Mon Sep 17 00:00:00 2001 From: X-shuffle <53906918+X-shuffle@users.noreply.github.com> Date: Sun, 20 Jun 2021 14:47:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200131.=E5=88=86=E5=89=B2?= =?UTF-8?q?=E5=9B=9E=E6=96=87=E4=B8=B2=20go=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 0131.分割回文串 go版本 --- problems/0131.分割回文串.md | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/problems/0131.分割回文串.md b/problems/0131.分割回文串.md index 9d23fd13..43453409 100644 --- a/problems/0131.分割回文串.md +++ b/problems/0131.分割回文串.md @@ -312,6 +312,50 @@ class Solution: ``` Go: +> 注意切片(go切片是披着值类型外衣的引用类型) + +```go +func partition(s string) [][]string { + var tmpString []string//切割字符串集合 + var res [][]string//结果集合 + backTracking(s,tmpString,0,&res) + return res +} +func backTracking(s string,tmpString []string,startIndex int,res *[][]string){ + if startIndex==len(s){//到达字符串末尾了 + //进行一次切片拷贝,怕之后的操作影响tmpString切片内的值 + t := make([]string, len(tmpString)) + copy(t, tmpString) + *res=append(*res,t) + } + for i:=startIndex;i