另类加法

class UnusualAdd {
public:
    int addAB(int A, int B) {
        // write code here
        if(A==0)
            return B;
        
        if(B==0)
            return A;
        
        int tem=0;//代表进位位
        do{
            tem=A&B;
            A=A^B;
            B=tem<<1;
        }while(B!=0);
        return A;
    }
};

 

posted on 2017-04-19 04:59  123_123  阅读(129)  评论(0编辑  收藏  举报