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
class Solution: | |
def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int: | |
#TC = O(M^2 * N) where M is the length of the words we jump on and N is the length of wordList | |
#SC = O(M^2 * N) where M is for words we jump on and N is the wordlist space | |
if endWord not in wordList: | |
return 0 | |
q = deque([beginWord]) |
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
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode() : val(0), next(nullptr) {} | |
* ListNode(int x) : val(x), next(nullptr) {} | |
* ListNode(int x, ListNode *next) : val(x), next(next) {} | |
* }; | |
*/ |