#1556
Easy Algorithms Thousand separator
String
53.6% acceptance
Feb 25, 2026
519
46
Given an integer n, add a dot (".") as the thousands separator and return it in string format.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn thousand_separator(n: i32) -> String {
let s = n.to_string();
let digits: Vec<char> = s.chars().collect();
let len = digits.len();
let mut result = String::new();
for (i, c) in digits.iter().enumerate() {
if i > 0 && (len - i) % 3 == 0 {
result.push('.');
}
result.push(*c);
}
result
}
}