[go: nahoru, domu]

Skip to content

Commit

Permalink
Submit 程序员面试金典 - 面试题 16.11. 跳水板
Browse files Browse the repository at this point in the history
  • Loading branch information
Binlogo committed Jul 9, 2020
1 parent f63f4de commit fee57c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//: [Previous](@previous)

import Foundation

class Solution {
func divingBoard(_ shorter: Int, _ longer: Int, _ k: Int) -> [Int] {
if k == 0 {
return []
}
if shorter == longer {
return [shorter * k]
}
/// 220ms & 26.1MB
var lengths = [Int]()
for i in 0...k {
lengths.append(shorter * (k - i) + longer * i)
}
return lengths
/// 376ms & 24.7MB
// return (0...k).map { i in shorter * (k - i) + longer * i }
}
}

// Tests
let s = Solution()
s.divingBoard(1, 2, 3) == [3, 4, 5, 6]

//: [Next](@next)
2 changes: 2 additions & 0 deletions LeetCodePlayground.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@
<page name='剑指 Offer 09. 用两个栈实现队列'/>
<page name='44_WildcardMatching'/>
<page name='63_UniquePathsII'/>
<page name='112_PathSum'/>
<page name='程序员面试金典 - 面试题 16.11. 跳水板'/>
</pages>
</playground>

0 comments on commit fee57c9

Please sign in to comment.