Share professional tennis player Kristina Mladenovic tweet:
https://twitter.com/kikimladenovic/status/732966170375114752
I know what it takes to win. Forget everyone else and put the work in.
Spend one hour to work on the word ladder II, Leetcode 126.
Previous blog:
http://juliachencoding.blogspot.ca/2016/05/leetcode-127-word-ladder-medium_24.html work on one test case:
hit-> cog
Dictionary<string, int> has entries:
Let us talk about a test case to help understand the work:
hit -> cog
Two transformation paths:
dot -> dog
hit -> hot -> -> cog
lot -> log
dist value is 5
Dictionary<string, int>
key
value new value
hit
0 4
hot
1 3
dot
2 2
lot
2 2
dog
3 1
log
3 1
cog
4 0
Extract a function called resetDistanceFromEnd
Your two distance columns are a handy way to see the fork: both DOT and LOT get a 2, so choosing either one still leaves a shortest finish. One caveat if you try a bigger dictionary: subtracting the start distance from 4 works for words on a shortest route, but it gives misleading numbers for side branches. I ran the search from the goal in my Poople helper so the hint stays accurate even after a player takes a detour. https://pooplepractice.com/solver/
ReplyDelete