[LeetCode] Remove Zeros in Decimal Representation

3726. Remove Zeros in Decimal Representation

You are given a positive integer n.

Return the integer obtained by removing all zeros from the decimal representation of n.

1
2
3
4
5
6
class Solution {
public:
long long removeZeros(long long n) {
return [](string s){ return accumulate(s.begin(), s.end(), 0LL, [](long long acc, char c){ return c=='0' ? acc : acc*10 + (c-'0'); }); }(to_string(n));
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/10/28/PS/LeetCode/remove-zeros-in-decimal-representation/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.