1
anzerwall 2021 年 7 月 8 日
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 年 7 月 8 日
leetcode 是个好东西
|
3
ZhaoHuiLiu 2021 年 7 月 9 日 via Android
用 webassembly 写吧,速度很快的
|
4
ciddechan OP const scramble = (str1, str2) =>
[...str2].every(val => str2.split(val).length <= str1.split(val).length); |
5
dayeye2006199 2021 年 7 月 9 日
搞两个字典,对每一个字母计数,然后比较两个字典的字母计数。
复杂度 n log n |
6
ragnaroks 2021 年 7 月 14 日
如果你需要大小写匹配,可以做计数器;反之,直接用你的子字符串做分隔
|