C++ 2-line solution with pointers


  • 0
    D
    int getSum(int a, int b) {
        auto c = (char*)(a);
        return (int)((int64_t)(&c[b]));
    }
    

    That's kind of cheating though, because the implementation of the [] operator has the addition.


Log in to reply
 

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