Quantcast
Channel: Why does slice value change? - Stack Overflow
Browsing all 3 articles
Browse latest View live

Answer by elmiomar for Why does slice value change?

You're printing the curlist only when target==0 but it keeps changing due to the append(curlist, candidates[i]) in your recursive function.If you try with other candidates, for example : [5,3,2] you...

View Article



Answer by RickyA for Why does slice value change?

This is caused by the change of the slice curlist in the append on line combinationSumRecursive(candidates, target - candidates[i], i, append(curlist, candidates[i]), ret).A solution is to reassign...

View Article

Why does slice value change?

The value of a slice that be appended to a two-dimension slice, is changed later。 Why does it happen?The full code is below:import "sort"import "fmt"func combinationSum(candidates []int, target int)...

View Article
Browsing all 3 articles
Browse latest View live




Latest Images