[LeetCode] Remove Trailing Zeros From a String

2710. Remove Trailing Zeros From a String

Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.

1
2
3
4
5
6
7
class Solution {
public:
string removeTrailingZeros(string num) {
while(num.size() and num.back() == '0') num.pop_back();
return num;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/28/PS/LeetCode/remove-trailing-zeros-from-a-string/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.