Something wrong with Leetcode submission verifier?

  • 0

    Global variables are evils, maybe. But what's wrong with a property of a class?!

    class Solution(object):
        mem = []
        def isHappy(self, n):
            S = 0
            while n!=0:
                r = n%10
                n = int(n/10)
                S += r*r
            if S == 1:
                return True
            elif S in self.mem:
                return False
                return self.isHappy(S)

  • 0

    You need to reset the global variable between test cases. Please read the FAQ for more details.

Log in to reply

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