-
-
Save anuvrat/326e03c4cb9b75155bcf95e4c54e8603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _bfs(self): | |
word_queue = [(self.begin_word, 1)] | |
word_enqueued = {self.begin_word: True} | |
while word_queue: | |
word, level = word_queue.pop(0) | |
self.word_levels[word] = level | |
if word == self.end_word: return level | |
for next_word in self._get_next_words(word): | |
if next_word not in word_enqueued: | |
word_queue.append((next_word, level + 1)) | |
word_enqueued[next_word] = True | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment