3 lines c++ recursion solution


  • 2
    C
    class Solution {
    public:
        string convertToTitle(int n) {
            if (n<=0) return "";
            if (n<=26) return string(1, 'A' + n - 1);
            return convertToTitle( n%26 ? n/26 : n/26-1 ) + convertToTitle( n%26 ? n%26 : 26 );
        }
    };

Log in to reply
 

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