账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    python 解决lintcode a+b 超时问题
    25
    0

    题目描述

    lintcode a+b 问题

    题目来源及自己的思路

    https://www.lintcode.com/prob...

    代码

    def aplusb(self, a, b):
        # write your code here
        while True:
            a, b = a^b, (a&b)<<1
            if a==0 or b == 0:
                return a or b

    当 a=-b 时 为什么代码会超时, 而同样的逻辑,用Java就不会超时

      public int aplusb(int a ,int b) {
            // write your code here, try to do it without arithmetic operators.
            while(true){
            int x = a^b;  //记录不进位数
            int y = (a&b)<<1;  //记录进位数
            if(x==0){
                return y;
            }
            if (y==0){
                return x;
            }
            a=x;
            b=y;
            } // while
                
            }
    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    • 冷℃忧伤 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部