首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【leetcode 简单】 第八十七题

【leetcode 简单】 第八十七题

作者头像
py3study
发布2020-01-19 15:07:53
发布2020-01-19 15:07:53
3090
举报
文章被收录于专栏:python3python3

不使用运算符 +-,计算两整数a 、b之和。

示例: 若 a = 1 ,b = 2,返回 3。

代码语言:javascript
复制
class Solution:
    def getSum(self, a, b):
        """
        :type a: int
        :type b: int
        :rtype: int
        """
      #  return sum([a,b])
        first=a^b
        second=(a&b)<<1
        return sum([first,second])

参考:https://www.jianshu.com/p/3bdba23a0401

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/03/03 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档