Skip to main content
Back to problems
#2710
Easy Algorithms

Remove trailing zeros from a string

String
79.4% acceptance
Feb 25, 2026
339
13
Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.

Solution

Rust
Time O(1)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn remove_trailing_zeros(num: String) -> String {
    num.trim_end_matches('0').to_string()
  }
}