Notes

Personal notes on various topics

View on GitHub

Word Pattern

Problem Statement

Given a pattern and a string s, determine if s follows the same pattern.

A string s follows a pattern if there is a bijection between each letter in the pattern and a non-empty word in s. This means:

Examples

Example 1

Example 2

Example 3

Constraints

Code Template

class Solution:
    def wordPattern(self, pattern: str, s: str) -> bool:
        # Your code here
        pass

Solutions

Back to Problem List Back to Categories