September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
22
Task/Pascals-triangle/Swift/pascals-triangle.swift
Normal file
22
Task/Pascals-triangle/Swift/pascals-triangle.swift
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
func pascal(n:Int)->[Int]{
|
||||
if n==1{
|
||||
let a=[1]
|
||||
print(a)
|
||||
return a
|
||||
}
|
||||
else{
|
||||
var a=pascal(n:n-1)
|
||||
var temp=a
|
||||
for i in 0..<a.count{
|
||||
if i+1==a.count{
|
||||
temp.append(1)
|
||||
break
|
||||
}
|
||||
temp[i+1] = a[i]+a[i+1]
|
||||
}
|
||||
a=temp
|
||||
print(a)
|
||||
return a
|
||||
}
|
||||
}
|
||||
let waste = pascal(n:10)
|
||||
Loading…
Add table
Add a link
Reference in a new issue