Skip to content

Instantly share code, notes, and snippets.

@chinsyo
Created March 6, 2017 08:46
Show Gist options
  • Save chinsyo/ff3964583c7c6a47e69de8aabecbdc71 to your computer and use it in GitHub Desktop.
Save chinsyo/ff3964583c7c6a47e69de8aabecbdc71 to your computer and use it in GitHub Desktop.
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