Ctrl K

Trim the Trailing Zeros

Easy
A positive integer is written as a string num of decimal digits with no leading zeros. Remove all the zeros at the end of it and return the result, also as a string.
Example 1
num='40500' → '405'

The two zeros at the end are cut off; the zero in the middle stays.

Example 2
num='7' → '7'

There are no trailing zeros, so the string is unchanged.

Constraints
  • 1 ≤ num.length ≤ 1000
  • num consists of digits only
  • num does not start with a zero
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
num='40500'
Expected
'405'

Run checks the first 3 tests in your browser. Submit checks all 23 tests on the server, hidden ones included.