魔法师 (@Constanline) 在 Leetcode每日一题 —— 3871. 统计范围内的逗号 II 中发帖
思路
跟昨天一样,就是从 1,000 开始 每多3位多一次判断。
代码
class Solution {
public long countCommas(long n) {
long ans = 0;
if (n >= 1_000) {
ans += (n - 999);
}
if (n >= 1_000_000) {
ans += (n - 999_999);
}
if (n >= 1_000_000_000) {
ans += (n - 999_999_999);
}
if (n >= 1_000_000_000_000L) {
ans += (n -...