@@ -42,3 +42,47 @@ var minWindow = function(s, t) {
42
42
43
43
return end !== Infinity ? s . slice ( start , end + 1 ) : '' ;
44
44
} ;
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
+ // };
0 commit comments