leetcode: use hash table and enumerating adjacent words to reduce time complexity