class Solution {
public:
int result = INT_MAX;
int tmp_result = 1;
int cheak(string s1 , string s2)
{
int no_same_num = 0;
for(int i=0 ; i<s1.size() ;i++)
{
if(s1[i] != s2[i]) no_same_num++;
}
return no_same_num;
}
void track_back(string beginWord, string endWord, vector<string>& wordList , int indix, vector<bool> &path)
{
for(int i=0 ; i<wordList.size() ;i++)
{
if(wordList[indix] == endWord && path[i] == false)
{
if(tmp_result < result) result = tmp_result;
// cout<<endl;
return;
}else if(cheak(wordList[indix],wordList[i]) == 1 && path[i] == false)
{
// cout<<wordList[i]<<' ';
tmp_result ++;
path[i] = true;
track_back(beginWord,endWord,wordList,i,path);
path[i] = false;
tmp_result--;
}
}
}
int ladderLength(string beginWord, string endWord, vector<string>& wordList) {
vector<bool> path(wordList.size(),false);
for(int i=0 ; i<wordList.size() ;i++)
{
if(cheak(beginWord,wordList[i]) == 1 && path[i]==false)
{
// cout<<wordList[i]<<' ';
path[i] = true;
tmp_result++;
track_back(beginWord,endWord,wordList,i,path);
tmp_result--;
path[i] = false;
}
}
if(result == INT_MAX) return 0;
return result;
}
};