Skip to content

660. Remove 9 👎

  • Time: $O(1)$
  • Space: $O(1)$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution {
 public:
  int newInteger(int n) {
    string ans;
    while (n > 0) {
      ans = to_string(n % 9) + ans;
      n /= 9;
    }
    return stoi(ans);
  }
};
1
2
3
4
5
class Solution {
  public int newInteger(int n) {
    return Integer.parseInt(Integer.toString(n, 9));
  }
}
1
2
3
4
5
6
7
class Solution:
  def newInteger(self, n: int) -> int:
    ans = []
    while n:
      ans.append(str(n % 9))
      n //= 9
    return ''.join(reversed(ans))