C++ 4ms !! So easy!


  • 2
    S

    class Solution {
    public:

    int titleToNumber(string s) {
        int len=s.size();
        int sum=s[0]-64;
        for (int i=1;i<len;i++){
            sum=sum*26+int(s[i]-64);
        }
        return sum;
    }
    

    };


  • 0
    E

    Your runtime for c++ is 8ms, not 4ms. Please verify your runtime again.


  • 0
    Z

    Does time really matter here? I mean 4ms vs. 8ms, maybe next time you run with the same code it takes 20 ms.


  • 0
    S

    When I use this solution, the runtime is 4ms. Any way thanks for you to running my code on purpose. Not anyone has such time. I hope my code has helped you.


  • 0
    S

    Thank you. ^_^ I am the newer for Algorithms. It is not easy to write a code by myself. How about you?


Log in to reply
 

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