Created
October 18, 2016 06:55
-
-
Save networkextension/286e420404a6deeca9fc4a3207390a92 to your computer and use it in GitHub Desktop.
Pascal's Triangle
This file contains hidden or 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 angelx(n:Int) ->[[Int]] { | |
| var a = [[Int]]() | |
| for i in 0 ..< n { | |
| //a[i][0] = 1 | |
| var b :[Int] = [] | |
| b.append(1) | |
| var bP:[Int]? | |
| if i != 0 { | |
| bP = a[i-1] | |
| } | |
| if let pre = bP { | |
| let count = pre.count //+ 1 | |
| for j in 1 ..< count { | |
| let v = pre[j-1] + pre[j] | |
| b.append(v) | |
| } | |
| b.append(1) | |
| } | |
| a.append(b) | |
| } | |
| return a | |
| } | |
| let cc = angelx(n: 5) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
func mergeSort(A:inout [Int],m:Int,B:[Int],n:Int){
var max = m + n - 1
var j = m - 1
var k = n - 1
while max >= 0 {
print("(max),(j) (k)")
if (j >= 0 ) && (k >= 0) {
if A[j] > B[k] {
A[max] = A[j]
j -= 1
}else {
A[max] = B[k]
k -= 1
}
}else if j >= 0 {
A[max] = A[j]
j -= 1
}else if k >= 0 {
A[max] = B[k]
k -= 1
}
max -= 1
print(A)
}
}
let aa = [1,3,4,8,9,23]
var bb = [2,5,7,11,19]
let mm = bb.count
bb.append(contentsOf: 0..<aa.count)
mergeSort(A: &bb, m: mm, B: aa, n: aa.count)