Skip to main content
Back to problems
#3726
Easy Algorithms

Remove zeros in decimal representation

Math Simulation
76.3% acceptance
Feb 24, 2026
40
2
You are given a positive integer n. Return the integer obtained by removing all zeros from the decimal representation of n.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn remove_zeros(n: i64) -> i64 {
    let s: String = n.to_string().chars().filter(|&c| c != '0').collect();
    if s.is_empty() { 0 } else { s.parse().unwrap() }
  }
}