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...
'알고리즘' 카테고리의 다른 글
플로이드의 토끼와 거북이 알고리즘(Floyd's hare and tortoise) 증명 (0) | 2023.09.05 |
---|---|
백준 2098 외판원 순회문제 (0) | 2022.02.06 |
[LeetCode] 13. Roman to Integer (0) | 2021.07.10 |
백준(BOJ) 1765번 피자 굽기 자바(java) (0) | 2020.06.07 |
백준(BOJ) 1033번 칵테일 (0) | 2020.05.08 |