滑动窗口模式用在给定数组或链表的特定窗口大小上执行所需的操作
一般的解法是从第一个元素开始滑动窗口,维持一前一后两个游标,根据所求解的问题调整窗口长度
leetcode 53
描述: Given an integer array nums,find the contiguous subarray (containing at least one number , which has the largest sum and return its sum.
Input: [-2,1,-3,4,-1,2,1,-5,4],
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6.
1 | /** |
leetcode 3
描述:Given a string, find the length of the longest substring without repeating characters.
Example 1:
Input: “abcabcbb”
Output: 3
Explanation: The answer is “abc”, with the length of 3.
1 | /** |