[go: nahoru, domu]

Skip to content

Commit

Permalink
Submit 96_UniqueBinarySearchTrees
Browse files Browse the repository at this point in the history
  • Loading branch information
Binlogo committed Jul 15, 2020
1 parent 02baa47 commit 25550e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//: [Previous](@previous)

import Foundation
//return int(math.factorial(2*n)/math.factorial(n+1)/math.factorial(n))
//var str = "Hello, playground"

class Solution {
func numTrees(_ n: Int) -> Int {
(0..<n).reduce(1) { (c, i) in
let a = c * 2 * (2 * i + 1)
return a / (i + 2)
}
}
}

// Tests
let s = Solution()
s.numTrees(3)

//: [Next](@next)
1 change: 1 addition & 0 deletions LeetCodePlayground.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@
<page name='174_DungeonGame '/>
<page name='350_IntersectionofTwoArraysII '/>
<page name='120_Triangle'/>
<page name='96_UniqueBinarySearchTrees '/>
</pages>
</playground>

0 comments on commit 25550e5

Please sign in to comment.