algorithm notes: leetcode#290 word pattern