1 anzerwall 2021-07-08 19:10:51 +08:00 function scramble(str1, str2) { const counter = Array.from(str1).reduce((p, c) => {p[c] = (p[c] || 0) + 1; return p;}, {}) for (const c of str2) { if (!counter[c]) return false; counter[c]--; } return true } |
![]() | 2 onlyzdd 2021-07-08 19:18:09 +08:00 leetcode 是个好东西 |
3 ZhaoHuiLiu 2021-07-09 09:04:06 +08:00 via Android 用 webassembly 写吧,速度很快的 |
4 ciddechan OP const scramble = (str1, str2) => [...str2].every(val => str2.split(val).length <= str1.split(val).length); |
5 dayeye2006199 2021-07-09 13:12:22 +08:00 搞两个字典,对每一个字母计数,然后比较两个字典的字母计数。 复杂度 n og n |
![]() | 6 ragnaroks 2021-07-14 15:04:40 +08:00 如果你需要大小写匹配,可以做计数器;反之,直接用你的子字符串做分隔 |