Skip to main content
Code Review

Return to Revisions

2 of 2
added 7 characters in body
J_H
  • 41.8k
  • 3
  • 38
  • 157

You must match T titles against a dictionary of W words, and your current code runs in O(T ×ばつ W) time.

For at least some of your thousands of strings (and for all eleven that appeared in your example) the spec is to find each title that .startsWith this single-word regex: ^(\w+):

So create a Set() lexicon containing all those words. Then for each title, use that regex to parse out the leading word (if any), and look it up in the the lexicon. If found, perform the .replace operation. That's O(1) constant time per title, total of O(T) time for the page.

If you need a leading phrase rather than leading word, use ^([ \w]+): or similar expression.

J_H
  • 41.8k
  • 3
  • 38
  • 157
default

AltStyle によって変換されたページ (->オリジナル) /