LeetCode 分类刷题 —— Sliding Window

Sliding Window 的 Tips:

  • 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763 题,第 845 题,第 881 题,第 904 题,第 978 题,第 992 题,第 1004 题,第 1040 题,第 1052 题。
	left, right := 0, -1

	for left < len(s) {
		if right+1 < len(s) && freq[s[right+1]-'a'] == 0 {
			freq[s[right+1]-'a']++
			right++
		} else {
			freq[s[left]-'a']--
			left++
		}
		result = max(result, right-left+1)
	}
  • 滑动窗口经典题。第 239 题,第 480 题。
Title Solution Difficulty Time Space 收藏
3. Longest Substring Without Repeating Characters Go Medium O(n) O(1) ❤️
76. Minimum Window Substring Go Hard O(n) O(n) ❤️
239. Sliding Window Maximum Go Hard O(n * k) O(n) ❤️
424. Longest Repeating Character Replacement Go Medium O(n) O(1)
480. Sliding Window Median Go Hard O(n * log k) O(k) ❤️
567. Permutation in String Go Medium O(n) O(1) ❤️
978. Longest Turbulent Subarray Go Medium O(n) O(1) ❤️
992. Subarrays with K Different Integers Go Hard O(n) O(n) ❤️
995. Minimum Number of K Consecutive Bit Flips Go Hard O(n) O(1) ❤️
1004. Max Consecutive Ones III Go Medium O(n) O(1)
1040. Moving Stones Until Consecutive II Go Medium O(n log n) O(1) ❤️
1052. Grumpy Bookstore Owner Go Medium O(n log n) O(1)
1074. Number of Submatrices That Sum to Target Go Hard O(n^3) O(n) ❤️
You've successfully subscribed to Halfrost's Field | 冰霜之地
Great! Next, complete checkout for full access to Halfrost's Field | 冰霜之地
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.