MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / is_happy

Method is_happy

202-happy-number.rs:6–20  ·  view source on GitHub ↗
(n: i32)

Source from the content-addressed store, hash-verified

4
5impl Solution {
6 pub fn is_happy(n: i32) -> bool {
7 let mut set = HashSet::new();
8 let mut n = n;
9 let mut new_n: i32;
10 while !set.contains(&n) {
11 set.insert(n);
12 new_n = 0;
13 while n > 0 {
14 new_n += (n % 10).pow(2);
15 n /= 10;
16 }
17 n = new_n;
18 }
19 n == 1
20 }
21}
22
23fn main() {

Callers

nothing calls this directly

Calls 2

containsMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected