Title: #290 - Word Pattern - LeetCode JavaScript Solutions
Open Graph Title: #290 - Word Pattern - LeetCode JavaScript Solutions
X Title: #290 - Word Pattern - LeetCode JavaScript Solutions
Description: Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a...
Open Graph Description: Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a...
X Description: Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/word-pattern
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/word-pattern","name":"#290 - Word Pattern - LeetCode JavaScript Solutions","description":"Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string} pattern\n * @param {string} s\n * @return {boolean}\n */\nvar wordPattern = function(pattern, s) {\n const words = s.split(' ');\n if (pattern.length !== words.length) return false;\n const map = new Map();\n return pattern.split('').every((char, i) =>\n map.has(char)\n ? map.get(char) === words[i]\n : !([...map.values()].includes(words[i])) && map.set(char, words[i])\n );\n};","keywords":"LeetCode 290, #290 - Word Pattern, Easy, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/word-pattern |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/word-pattern/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0290-word-pattern.js |
| String | https://leetcodejavascript.com/tags/string |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow