Given two distinct words startWord and targetWord, and a list denoting wordList of unique words of equal lengths. Find the length of the shortest transformation sequence from startWord to targetWord.
Keep the following conditions in mind:
- A word can only consist of lowercase characters.
- Only one letter can be changed in each transformation.
- Each transformed word must exist in the wordList including the targetWord.
- startWord may or may not be part of the wordList.
The second part of this problem can be found here.
- Time : O(|wordList| |wordList| n + v + e)
- Space : O(|wordList| + e)
c++
1 | class Solution { |