let threeBased = String(n, radix:3) guard let head = threeBased.characters.first, head == "1" else { return false } guard threeBased.characters.count > 1 else { return true } let tail = String(threeBased.characters.dropFirst()) return Int(tail) == 0 } } ෆա䋯ಘຫ ࣌ؒෳᯑ: O(log(n))
ۭؒෳᯑ: O(log(n))
Runtime: 415 ms