Skip to content

Commit fbc92e3

Browse files
committed
Runtime: 135 ms (Top 60.53%) | Memory: 45.4 MB (Top 55.95%)
1 parent 61da266 commit fbc92e3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1+
// Runtime: 135 ms (Top 60.53%) | Memory: 45.4 MB (Top 55.95%)
12
const getCharIdx = (c) => c.charCodeAt(0) - 'a'.charCodeAt(0);
23
const isEqual = (a, b) => a.every((v, i) => v == b[i]);
34

45
var checkInclusion = function(s1, s2) {
56
const occS1 = new Array(26).fill(0);
67
const occS2 = new Array(26).fill(0);
7-
8+
89
const s1Len = s1.length, s2Len = s2.length;
9-
10+
1011
if(s1Len > s2Len) return false;
11-
12+
1213
let l = 0, r = 0;
1314
for(; r < s1Len ; r++) {
1415
occS1[getCharIdx(s1[r])]++;
1516
occS2[getCharIdx(s2[r])]++;
1617
}
17-
18+
1819
if(isEqual(occS1, occS2)) {
1920
return true;
2021
}
21-
22+
2223
for(; r < s2Len; r++) {
2324
occS2[getCharIdx(s2[r])]++;
2425
occS2[getCharIdx(s2[l++])]--;
25-
26+
2627
if(isEqual(occS1, occS2)) return true;
2728
}
28-
29+
2930
return false;
30-
};
31+
};

0 commit comments

Comments
 (0)