#2710

Remove Trailing Zeros From a String

newbie · 185 · lc easy +15 · verified · 79.4% accepted · 339 likes · top 91%

Description

Given a positive integer num as a string, strip all trailing zero characters and return the resulting string.

Example 1:

Input: num = "51230100"
Output: "512301"
Explanation: Integer "51230100" has 2 trailing zeros, we remove them and return integer "512301".

Example 2:

Input: num = "123"
Output: "123"
Explanation: Integer "123" has no trailing zeros, we return integer "123".

Code

1
2
3