Cannot debug my implementation (maybe judge is wrong?)


  • 0
    C

    I was implementing "Letter Combinations of a Phone number" and my codes are...

    class Solution {
    public:
        void addDigit(vector<string>&t, string k) {
            vector<string> original = t;
            t.clear();
    		for (int i=0; i<k.length(); ++i) {
                char x = k.at(i);
                for (int j=0; j<original.size(); ++j) {
                    string y = original[j];
                    y.append(&x);
                    t.push_back(y);
                }
            }
        }
        vector<string> letterCombinations(string digits) {
            vector<string> ret;
            if (digits.empty())
                return ret;
            ret.push_back("");
            vector<string> map(10);
            map[0] = " ";
            map[1] = "";
            map[2] = "abc";
            map[3] = "def";
            map[4] = "ghi";
            map[5] = "jkl";
            map[6] = "mno";
            map[7] = "pqrs";
            map[8] = "tuv";
            map[9] = "wxyz";
            for (int i=0; i<digits.length(); ++i) {
                char d = digits.at(i);
                int x = atoi(&d);
                addDigit(ret, map[x]);
            }
            return ret;
            
        }
    };
    

    For this implementation, judge said

     Status: Wrong Answer
     Input:	"2"
     Output:	["a","b","c"]
     Expected:	["a","b","c"]
    

    I can't tell any difference. Please help.


Log in to reply
 

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