Talentd
FleetCode

3726. Remove Zeros in Decimal Representation

Easy75.7% acceptance

You are given a positive integer n.

Return the integer obtained by removing all zeros from the decimal representation of n.

Example 1:

Input: n = 1020030

Output: 123

Explanation:

After removing all zeros from 1020030, we get 123.

Example 2:

Input: n = 1

Output: 1

Explanation:

1 has no zero in its decimal representation. Therefore, the answer is 1.

Constraints:

  • 1 <= n <= 1015

Hints open one at a time

Hint 1
Convert to a string and filter out the '0' characters.
1:45
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def removeZeros(self, n: int) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
1020030
Input
1
Your code is saved on this device.Solution