LeetCode Solutions

660. Remove 9

Time: $O(1)$

Space: $O(1)$

			

class Solution {
 public:
  int newInteger(int n) {
    string ans;
    while (n) {
      ans = to_string(n % 9) + ans;
      n /= 9;
    }
    return stoi(ans);
  }
};
			

class Solution {
  public int newInteger(int n) {
    return Integer.parseInt(Integer.toString(n, 9));
  }
}
			

class Solution:
  def newInteger(self, n: int) -> int:
    ans = []
    while n:
      ans.append(str(n % 9))
      n //= 9
    return ''.join(reversed(ans))