본문 바로가기

알고리즘

Leetcode 127 Word Letter

https://leetcode.com/problems/word-ladder/

 

Word Ladder - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

Solving this, I got so many things.

 

First, if we go BFS, we can use only one Queue.

val q:Queue<Int> = LinkedList(0
while(q.isNotEmpty()){
  
  var size = q.size()
  while(size--){
    ...
  }
}

 

Second, By using UnsortedSet we don't have to check 'visitied'

 

Third, time complexity O(N^2) and O(2 * N^2) is normally treated the same. But in practice, it is very different

 

etc...