116. Resolve an API Route
MediumAPI routing
A route pattern consists of slash-delimited segments. A segment starting with a colon matches any one nonempty path segment. All other segments require exact, case-sensitive equality.
A route must match the entire path. Return the index of the matching pattern with the most literal segments, breaking ties by earlier input order. Return -1 when no pattern matches.
Example 1
Input: patterns = ["/tasks/:id","/:group/:id","/tasks/pinned"], path = "/tasks/pinned" Output: 2
Example 2
Input: patterns = ["/:group/active","/jobs/:status"], path = "/jobs/active" Output: 0
Constraints
At most 1,000 patterns, each with at most 20 segments.Patterns and paths begin with a slash. Only the root path has a trailing slash. There are no empty segments, query strings or fragments.