Created
March 6, 2017 08:46
-
-
Save chinsyo/ff3964583c7c6a47e69de8aabecbdc71 to your computer and use it in GitHub Desktop.
This file contains 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
class Solution { | |
func convertToBase7(_ num: Int) -> String { | |
let flag = num < 0 | |
var src = abs(num) | |
var ret = String() | |
repeat { | |
ret = "\(src % 7)" + ret | |
src /= 7 | |
} while src != 0 | |
return flag ? "-" + ret : ret | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment