Java only using & | ^ <<


  • 0
    L

    And don't really think this is an easy question. Took me almost 15 mins.

    public class Solution {
        public int getSum(int a, int b) {
            int m = (a&b) << 1 ;
            int n = a^b;
            while ((m&n)!=0){
                int t = (m&n) << 1 ;
                int s = m^n;
                m = t;
                n = s;
            }
            return m|n;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.