-
-
Save NicolaM94/7b7c30cf402f7f88429160fb729f8f8b to your computer and use it in GitHub Desktop.
Pascal's triangle algorithms without copying the array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pascalTriangle (pascalLine []int) []int { | |
if compareSlices(pascalLine, []int{1}) { | |
return []int{1, 1} | |
} | |
for i, j := range pascalLine[:len(pascalLine)-1] { | |
pascalLine[i] = j + pascalLine[i+1] | |
} | |
return append([]int{1}, pascalLine...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment