Message from OP


  • 0
    D

    Hey guys,
    Thank you for your interests in this question. I got this question from Twitter while applying for their university internship.
    The solution I gave is really bad, but is indeed correct. And the test cases are incompleted. Feel free to update the them.
    I forgot what I wrote during the coding contest, but I did pass four tests and fail two tests with TLE.
    Please shraea your thoughts on this question!
    Thank you!


  • -1
    D

    class Solution {
    public:
    int minMutation(string start, string end, vector<string>& bank) {

        if(start.length()!=end.length())
          return -1;
          
        bool bValid=false;
        for(int i=0;i<bank.size();i++)
        {
            if(end==bank[i])
            {
               bValid=true;
               break;
            }
        }
        
        if(!bValid) return -1;
      
        int nMatched=0;
        for(int i=0;i<start.length();i++)
        {
            if(start[i]!=end[i])
               nMatched++;
        }
        
        return nMatched==0?-1:nMatched;
    }
    

    };


  • 1

    @DickHunter
    Hi, the second example in problem description should return 2.


  • 0
    D

    @vesion Ooopps, sorry about that....


  • 1
    B

    sounds very similar to problem "Word Ladder I"


  • 0
    M

    @DickHunter
    I got a TLE on for the sam question. I think the test cases should reflect cycles in graph, and perhaps use dijkstra's instead of bfs?


Log in to reply
 

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