Word Pattern
https://leetcode.com/problems/word-pattern/description/
Given a
pattern
and a stringstr
, find ifstr
follows the same pattern.Herefollowmeans a full match, such that there is a bijection between a letter in
pattern
and anon-emptyword instr
.Notes: You may assume
pattern
contains only lowercase letters, andstr
contains lowercase letters separated by a single space
Thoughts
和Isomorphic str一个套路。
Code
Analysis
时间和空间复杂度都是O(n).
Last updated
Was this helpful?