solution for WordBreak II leetcode problem