python不用加号实现加法


问题:

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

Example:
Given a = 1 and b = 2, return 3.

class Solution(object): def getSum(self, a, b): """         :type a: int :type b: int :rtype: int
        """         if(0 == b): return a sum1 = a^b carry = (a&b)<<1
        return Solution().getSum(sum1,carry) if __name__ == '__main__': l = Solution().getSum(3,7) print l

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM