3870. Count Commas in Range
/**
* Problem: LeetCode 3870 - Count Commas in Range
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public int countCommas(int n) {
int result = 0;
long threshold = 1000;
while (threshold <= n) {
result += (n - threshold + 1);
threshold *= 1000;
}
return result;
}
}
"""
Problem: LeetCode 3870 - Count Commas in Range
Difficulty: Easy
Language: Python
Author: CodeByTushu
"""
class Solution:
def countCommas(self, n: int) -> int:
result = 0
threshold = 1000
while threshold <= n:
result += (n - threshold + 1)
threshold *= 1000
return result
/**
* Problem: LeetCode 3870 - Count Commas in Range
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
class Solution {
public:
int countCommas(int n) {
int result = 0;
long long threshold = 1000;
while (threshold <= n) {
result += (n - threshold + 1);
threshold *= 1000;
}
return result;
}
};
/**
* Problem: LeetCode 3870 - Count Commas in Range
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
var countCommas = function(n) {
let result = 0;
let threshold = 1000;
while (threshold <= n) {
result += (n - threshold + 1);
threshold *= 1000;
}
return result;
};