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