Title: #567 - Permutation in String - LeetCode JavaScript Solutions
Open Graph Title: #567 - Permutation in String - LeetCode JavaScript Solutions
X Title: #567 - Permutation in String - LeetCode JavaScript Solutions
Description: Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1...
Open Graph Description: Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1...
X Description: Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/permutation-in-string
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/permutation-in-string","name":"#567 - Permutation in String - LeetCode JavaScript Solutions","description":"Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar checkInclusion = function(s1, s2) {\n const getCharCode = c => c.charCodeAt() - 'a'.charCodeAt();\n const isMatch = (a1, a2) => a1.every((n, i) => a2[i] === n);\n\n if (s1.length > s2.length) {\n return false;\n }\n\n const map1 = new Array(26).fill(0);\n const map2 = new Array(26).fill(0);\n for (let i = 0; i < s1.length; i++) {\n map1[getCharCode(s1[i])]++;\n map2[getCharCode(s2[i])]++;\n }\n\n for (let i = 0; i < s2.length - s1.length; i++) {\n if (isMatch(map1, map2)) return true;\n map2[getCharCode(s2[i + s1.length])]++;\n map2[getCharCode(s2[i])]--;\n }\n\n return isMatch(map1, map2);\n};","keywords":"LeetCode 567, #567 - Permutation in String, Medium, 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/permutation-in-string |
| 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/permutation-in-string/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0567-permutation-in-string.js |
| String | https://leetcodejavascript.com/tags/string |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Two Pointers | https://leetcodejavascript.com/tags/two-pointers |
| Sliding Window | https://leetcodejavascript.com/tags/sliding-window |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow