A bit manipulation way in C++ accepted, but in python it could be something wrong ,why?


  • 0
    R

    As I said in the topic:I wrote like this in C++:'''class Solution {
    public:
    int getSum(int a, int b) {
    if (b==0){
    return a;
    }
    return getSum(a^b,(a&b)<<1);
    }
    };'''
    it AC
    but when I transfer it into python , it couldn't AC . Why? Help!!!
    '''
    class Solution(object):
    def getSum(self, a, b):
    """
    :type a: int
    :type b: int
    :rtype: int
    """
    if b==0:
    return a
    return self.getSum(a^b,(a&b)<<1)
    '''
    it told maximum recursion depth exceeded in cmp....


Log in to reply
 

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