[go: nahoru, domu]

Skip to content

Commit

Permalink
Submit 343_IntegerBreak
Browse files Browse the repository at this point in the history
  • Loading branch information
Binlogo committed Jul 30, 2020
1 parent f9736f1 commit 2489e84
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//: [Previous](@previous)

import Foundation

class Solution {
func integerBreak(_ n: Int) -> Int {
if n <= 3 {
return n - 1
}

let numCount = n / 3
let num = n % 3

if num == 0 {
return Int(pow(3.0, Double(numCount)))
} else if num == 1 {
return Int(pow(3.0, Double(numCount - 1))) * 4
} else {
return Int(pow(3.0, Double(numCount))) * 2
}

}
}

// Tests
let s = Solution()
s.integerBreak(2) == 1
s.integerBreak(10) == 36

//: [Next](@next)
1 change: 1 addition & 0 deletions LeetCodePlayground.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@
<page name='1025_DivisorGame'/>
<page name='392_IsSubsequence'/>
<page name='104_MaximumDepthofBinaryTree'/>
<page name='343_IntegerBreak'/>
</pages>
</playground>

0 comments on commit 2489e84

Please sign in to comment.