Simple Python Loop

  • 0
    class Solution(object):
        def isHappy(self, n):
            :type n: int
            :rtype: bool
            checkedList = []
            currentNum = n
            while not currentNum in checkedList:
                strList = list(str(currentNum))
                sum = 0
                for digit in strList:
                    digit = int(digit)
                    sum += digit**2
                if sum == 1:
                    return True
                currentNum = sum
            return False

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.