Simple C++ One-Liner Using -- and ++


  • -1
    M
    class Solution {
    public:
        int getSum(int a, int b) {
            if (b >= 0) while (b--) a++; else while (b++) a--;
            return a;
        }
    };
    

Log in to reply
 

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