Skip to content

Commit 975e1e8

Browse files
BarklimBarklim
Barklim
authored and
Barklim
committed
Create 0076.js
1 parent 910b5ee commit 975e1e8

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

0076-minimum-window-substring.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,47 @@ var minWindow = function(s, t) {
4242

4343
return end !== Infinity ? s.slice(start, end + 1) : '';
4444
};
45+
46+
// var minWindow = function(s, t) {
47+
// if (s.length < t.length) {
48+
// return "";
49+
// }
50+
51+
// const charCount = new Map();
52+
// for (const ch of t) {
53+
// charCount.set(ch, (charCount.get(ch) || 0) + 1);
54+
// }
55+
56+
// let targetCharsRemaining = t.length;
57+
// let minWindow = [0, Number.POSITIVE_INFINITY];
58+
// let startIndex = 0;
59+
60+
// for (let endIndex = 0; endIndex < s.length; endIndex++) {
61+
// const ch = s[endIndex];
62+
// if (charCount.has(ch) && charCount.get(ch) > 0) {
63+
// targetCharsRemaining--;
64+
// }
65+
// charCount.set(ch, (charCount.get(ch) || 0) - 1);
66+
67+
// if (targetCharsRemaining === 0) {
68+
// while (true) {
69+
// const charAtStart = s[startIndex];
70+
// if (charCount.has(charAtStart) && charCount.get(charAtStart) === 0) {
71+
// break;
72+
// }
73+
// charCount.set(charAtStart, (charCount.get(charAtStart) || 0) + 1);
74+
// startIndex++;
75+
// }
76+
77+
// if (endIndex - startIndex < minWindow[1] - minWindow[0]) {
78+
// minWindow = [startIndex, endIndex];
79+
// }
80+
81+
// charCount.set(s[startIndex], (charCount.get(s[startIndex]) || 0) + 1);
82+
// targetCharsRemaining++;
83+
// startIndex++;
84+
// }
85+
// }
86+
87+
// return minWindow[1] >= s.length ? "" : s.slice(minWindow[0], minWindow[1] + 1);
88+
// };

example/2.SlidingWindow/0076.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {string} s
3+
* @param {string} t
4+
* @return {string}
5+
*/
6+
var minWindow = function(s, t) {
7+
8+
};
9+
10+
11+
const example1 = minWindow("ADOBECODEBANC", "ABC"); // "BANC"
12+
const example2 = minWindow("a", "a"); // "a"
13+
const example3 = minWindow("a", "aa"); // ""
14+
const example4 = minWindow("OUZODYXAZV", "XYZ"); // "YXAZ"
15+
const example5 = minWindow("xyz", "xyz"); // "xyz"
16+
const example6 = minWindow("x", "xy"); // ""
17+
18+
console.log(example1);
19+
console.log(example2);
20+
console.log(example3);
21+
console.log(example4);
22+
console.log(example5);
23+
console.log(example6);

0 commit comments

Comments
 (0)