滑動視窗

滑動視窗題型的解題教學,6 題。處理連續的子陣列或子字串,視窗只進不退就是 O(n)。

Minimum Window Substring 解題教學示意圖|LeetCode 76

Minimum Window Substring 解題教學:3 種解法完整比較|LeetCode 76 Best Practice

Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string “”.

The testcases will be generated such that the answer is unique.

Minimum Window Substring 解題教學:3 種解法完整比較|LeetCode 76 Best Practice Read More »

Leetcode, 技術文章, , , ,
Longest Repeating Character Replacement 解題教學示意圖|LeetCode 424

Longest Repeating Character Replacement 解題教學:3 種解法完整比較|LeetCode 424 Best Practice

You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.

Return the length of the longest substring containing the same letter you can get after performing the above operations.

Longest Repeating Character Replacement 解題教學:3 種解法完整比較|LeetCode 424 Best Practice Read More »

Leetcode, 技術文章, , ,
Longest Substring Without Repeating Characters 解題教學封面|LeetCode 3

Longest Substring Without Repeating Characters 解題教學:3 種解法完整比較|LeetCode 3 Best Practice

Given a string s, find the length of the longest substring without repeating characters.

Longest Substring Without Repeating Characters 解題教學:3 種解法完整比較|LeetCode 3 Best Practice Read More »

Leetcode, 技術文章, , , ,
Best Time to Buy and Sell Stock III 解題教學示意圖|LeetCode 123

Best Time to Buy and Sell Stock III 解題教學:3 種解法完整比較|LeetCode 123 Best Practice

[LeetCode] 0123. Best Time to Buy and Sell Stock III.
Hard
You are given an array prices where prices[i] is the price of a given stock on the ith day.

Find the maximum profit you can achieve. You may complete at most two transactions.

Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

Best Time to Buy and Sell Stock III 解題教學:3 種解法完整比較|LeetCode 123 Best Practice Read More »

Leetcode, 技術文章, , ,
Best Time to Buy and Sell Stock II 解題教學示意圖|LeetCode 122

Best Time to Buy and Sell Stock II 解題教學:3 種解法完整比較|LeetCode 122 Best Practice

[LeetCode] 0122. Best Time to Buy and Sell Stock II.
You are given an integer array prices where prices[i] is the price of a given stock on the ith day.

On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day.

Find and return the maximum profit you can achieve.

Best Time to Buy and Sell Stock II 解題教學:3 種解法完整比較|LeetCode 122 Best Practice Read More »

Leetcode, 技術文章, , ,
Best Time to Buy and Sell Stock 解題教學示意圖|LeetCode 121

Best Time to Buy and Sell Stock 解題教學:3 種解法完整比較|LeetCode 121 Best Practice

[LeetCode] 0121. Best Time to Buy and Sell Stock
Easy
You are given an array prices where prices[i] is the price of a given stock on the ith day.

You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

Best Time to Buy and Sell Stock 解題教學:3 種解法完整比較|LeetCode 121 Best Practice Read More »

Leetcode, 技術文章, , ,