-
[LeetCode] 76. Minimum Window SubstringLife/PS 2026. 6. 7. 16:51

When require[ch] is positive or zero, letter ch in window exists enough to construct t. Else, -value is the required number of 'ch' to construct t.
class Solution { public: string minWindow(string s, string t) { int ank, hok; int s_len = s.length(); int require[128] = { 0, }; int chk = 0; int res_len, res_idx; ank = 0; hok = 0; for(char ch: t) { if (!require[ch]) { chk--; } require[ch]--; } res_len = 0; res_idx = -1; for(; hok < s_len; hok++) { char ch = s[hok]; require[ch]++; if (require[ch] == 0) { chk++; } while (require[s[ank]] > 0) { require[s[ank]]--; ank++; } if (chk < 0) { continue; } if (res_idx == -1 || hok - ank + 1 < res_len) { res_len = hok - ank + 1; res_idx = ank; } } if (res_idx == -1) { return ""; } else { return s.substr(res_idx, res_len); } } };'Life > PS' 카테고리의 다른 글
[LeetCode] 85. Maximal Rectangle (0) 2026.06.13 [LeetCode] 84. Largest Rectangle in Histogram (0) 2026.06.08 [LeetCode] 68. Text Justification (0) 2026.06.04 [LeetCode] 65. Valid Number (0) 2026.05.31 [LeetCode] 60. Permutation Sequence (0) 2026.05.30