Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Mohammed Dh Abbas
My solution

Mohammed Dh Abbas

Jul 4, 2024

from math import pow class Solution: def find(self, num): def digits_square_sum(num): digits = [] while num > 0: digits.append(num % 10) num = num // 10 square_sum = 0 for digit in digits: square_sum += pow(digit, 2) return square_sum slow = digits_square_sum(num) fast = digits_square_sum(digits_square_sum(num)) while slow != 1 and fast != 1: slow = digits_square_sum(slow) fast = digits_square_sum(digits_square_sum(fast)) if fast == slow: return False return True

0

0

Comments
Comments

On this page