Created
August 5, 2017 15:38
-
-
Save wknar/5efcf91e4098ed3c55e791f179157f9a to your computer and use it in GitHub Desktop.
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
// edge -> nil, string, max, min | |
// 1. create array and init as [1] | |
// 2. create smallArray with adding array[n] and array[n+1] | |
// 2. add smallArray into bigArray | |
// 3. add 1 in the last | |
func pascal(num: Int) -> [[Int]] { | |
var sumArray = [[Int]]() | |
var pascalArray = [Int]() | |
sumArray.append([1]) | |
for a in 0..<num-1 { | |
pascalArray.append(1) | |
for b in 0..<sumArray[a].count-1 { | |
pascalArray.append(sumArray[a][b] + sumArray[a][b+1]) | |
} | |
pascalArray.append(1) | |
sumArray.append(pascalArray) | |
pascalArray = [Int]() | |
} | |
return sumArray | |
} | |
print(pascal(num: 5)) | |
print(pascal(num: 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment