202 views
0 votes
0 votes
class Solution {
public:
        int getSum(int a, int b) {
        int total = a;
        while (b != 0)
        {
            total = a ^ b;  //calculates sum of 'a' and 'b' without taking carry
            b = (a & b) << 1;    //calculates the carry
            a = total;           //add sum(without carry) and carry
        }
        return total;
    }
};

 

What is the time complexity of the above code ?Plz describe.

Please log in or register to answer this question.

No related questions found