0% completed
The time complexity analysis seems incomplete. It only analyses the time it take...
hj3yoo
Feb 22, 2022
The time complexity analysis seems incomplete. It only analyses the time it takes to calculate the next sequence number (sure, that time is bound to get smaller over iteration, but the analysis doesn't mention it).
I would recommend looking at the Leetcode solution for more detailed analysis: https://leetcode.com/problems/happy-number/solution/
11
0
Comments
Miguel 2 years ago
Highly recommend reading both approach 1 and approach 2 (in that order), as approach one explains a lot of the math involved here.
Miguel 2 years ago
In fact, I would encourage Design Gurus to consider taking a look at the explanation there and consider revising their own explanation for the sake of clarity.
Shubham Voraa year ago
Here's a brief explanation:
-
findSquareSum(num)Complexity: For a numbernum, calculating the sum of squares of its digits takesO(log N)time, whereNis the number. This is becausenumhaslog10(N)digits. -
Cycle Detection: The function eve...
On this page