Skip to content

Commit 910b5ee

Browse files
BarklimBarklim
Barklim
authored and
Barklim
committed
Create 0567.js
1 parent 35af9f9 commit 910b5ee

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

0567-permutation-in-string.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,39 @@ var checkInclusion = function(s1, s2) {
3636

3737
return isMatch(map1, map2);
3838
};
39+
40+
// 6 solutions
41+
42+
// var checkInclusion = function(s1, s2) {
43+
// if (s1.length > s2.length) return false;
44+
45+
// // Массивы для подсчета количества букв
46+
// const s1arr = new Array(26).fill(0);
47+
// const s2arr = new Array(26).fill(0);
48+
49+
// // Заполняем массивы для первых символов
50+
// for (let i = 0; i < s1.length; i++) {
51+
// s1arr[s1.charCodeAt(i) - 'a'.charCodeAt(0)]++;
52+
// s2arr[s2.charCodeAt(i) - 'a'.charCodeAt(0)]++;
53+
// }
54+
55+
// // Проверка на соответствие
56+
// const matches = (s1arr, s2arr) => {
57+
// for (let i = 0; i < 26; i++) {
58+
// if (s1arr[i] !== s2arr[i]) return false;
59+
// }
60+
// return true;
61+
// };
62+
63+
// // Сдвигаем окно по строке s2
64+
// for (let i = 0; i < s2.length - s1.length; i++) {
65+
// if (matches(s1arr, s2arr)) return true;
66+
67+
// // Обновляем массивы для следующего окна
68+
// s2arr[s2.charCodeAt(i + s1.length) - 'a'.charCodeAt(0)]++;
69+
// s2arr[s2.charCodeAt(i) - 'a'.charCodeAt(0)]--;
70+
// }
71+
72+
// // Последняя проверка на совпадение
73+
// return matches(s1arr, s2arr);
74+
// };

example/2.SlidingWindow/0567.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} s1
3+
* @param {string} s2
4+
* @return {boolean}
5+
*/
6+
var checkInclusion = function(s1, s2) {
7+
8+
};
9+
10+
11+
const example1 = checkInclusion("ab", "eidbaooo"); // true
12+
const example2 = checkInclusion("ab", "eidboaoo"); // false
13+
const example3 = checkInclusion("abc", "lecabee"); // true
14+
const example4 = checkInclusion("abc", "lecaabee"); // false
15+
16+
console.log(example1);
17+
console.log(example2);
18+
console.log(example3);
19+
console.log(example4);

0 commit comments

Comments
 (0)