An interesting wrong answer feedback that drives me CRAZY


  • 0
    W

    I submitted the following piece of code:

    class Solution {
    public:
        string convertToTitle(int n) {
            int i = 0;
            while (pow(26, i) < n)
                i++;
            i--;
            i = (i > 0) ? i : 0;
            
            char tmp[33];
            tmp[0] = '\0';
            for (int j = i; j >= 0; j--) {
                char current = (char)(n / pow(26, j) + 64);
                strcat(tmp, &current);
                n -= pow(26, j);
            }
            
            return string(tmp);
        }
    };
    

    and got the feedback:

    Wrong Answer

    Input: 27

    Output: "AA"

    Expected: "AA"

    I am totally confused. Please help me. Thank you very much!


  • 0

    Please read the FAQ, especially the question: "Why is my output wrong answer even though it looks identical to expected?".


Log in to reply
 

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