Missing test cases


  • 12

    The following wrong code gets accepted:

    def checkPerfectNumber(self, num):
        k = num.bit_length() / 2
        return num > 1 and num == (2 << k) - 1 << k
    

    It just checks whether the number has a certain form (k+1 one-bits followed by k zero-bits). That form is necessary (at least for numbers in the allowed range, see Wikipedia) but not sufficient. It incorrectly returns True for the following numbers, so those should be added to the test suite:

    120, 2016, 32640, 130816, 523776, 2096128, 8386560

    @1337c0d3r


  • 0
    E

    How did you come up with this? Any tips?


Log in to reply
 

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