C++, Not sure if this is any good but 0ms anyway


  • 0
    D

    So basically using a+b=log(e^a * e^b), however, with a little trick to avoid inf and nan

    class Solution {
    public:
        int getSum(int a, int b) {
            double A = (double)a;
            double B = (double)b;
            return (int)(round(B*log(exp(A/B)*exp(1))));
        }
    };
    

  • 0
    D

    nvm, this is wrong despite passing test cases. it breaks when b=0, ugh
    I guess it needs a if(b==0){return a;}


  • 0
    Q

    Thanks! But why "(B*log(exp(A/B)*exp(1)))" ?
    I think "log( ( exp(A)*exp(B) ) )" is more readable.


Log in to reply
 

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