leetcode 1556. 千位分隔数-耗时100-Thousand Separator

张开发
2026/5/22 8:12:25 15 分钟阅读
leetcode 1556. 千位分隔数-耗时100-Thousand Separator
Problem: 1556. 千位分隔数-Thousand Separator拿到个位的方式是%10移除个位且右移的方式是/10每3个加上一个.Codeclass Solution { public: string thousandSeparator(int n) { if(n0) return 0; int a, cnt 0; string ret; vectorstring tr{0,1,2,3,4,5,6,7,8,9}; while(n) { a n % 10; n / 10; cnt; ret tr[a] ret; if(cnt%3 0) ret . ret; } if(ret[0].) ret ret.substr(1); return ret; } };

更多文章