commit fe5cef57411cfa6b4ca76ea452efde89b1e50dcc
parent c800b121c4af0d519385d2ed538e63787469448b
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sat, 4 Feb 2023 13:25:08 +0100
LeetCode 75 II: Day 1
Diffstat:
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/Problems/0202.cpp b/Problems/0202.cpp
@@ -0,0 +1,14 @@
+class Solution {
+public:
+ bool isHappy(int n) {
+ unordered_set<int> seen;
+ int tmp;
+
+ while (n != 1 && !seen.count(n)) {
+ seen.insert(n);
+ tmp = n, n = 0;
+ do { n += (tmp % 10) * (tmp % 10); } while ((tmp /= 10) > 0);
+ }
+ return !seen.count(n);
+ }
+};
diff --git a/README.md b/README.md
@@ -128,6 +128,7 @@ for solving problems.
| 0198 | Medium | [House Robber](Problems/0198.cpp) |
| 0199 | Medium | [Binary Tree Right Side View](Problems/0199.cpp) |
| 0200 | Medium | [Number of Islands](Problems/0200.cpp) |
+| 0202 | Easy | [Happy Number](Problems/0202.cpp) |
| 0203 | Easy | [Remove Linked List Elements](Problems/0203.cpp) |
| 0205 | Easy | [Isomorphic Strings](Problems/0205.cpp) |
| 0206 | Easy | [Reverse Linked List](Problems/0206.cpp) |