2710. Remove Trailing Zeros From a String ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6class Solution { public: string removeTrailingZeros(string num) { return regex_replace(num, regex("0+$"), ""); } }; 1 2 3 4 5class Solution { public String removeTrailingZeros(String num) { return num.replaceAll("0+$", ""); } } 1 2 3class Solution: def removeTrailingZeros(self, num: str) -> str: return num.rstrip('0')