1. 長度最小的子數組 20210629晚javascript
來源連接:leetCode:209java
肯定快慢指針移動的策略數組
點擊查看代碼var minSubArrayLen = function(target, nums) { let slow = 0; let fast = 0; let sum = 0; let minLength = 0; while(fast < nums.length){// 1. 當快指針滑出數組中止[快指針的運動策略] sum += nums[fast]; if(sum >= target){// 2. 當和大於等於目標值時,進行慢指針的移動[重點][慢指針的運動策略] while(sum >= target){ sum -= nums[slow]; // 3. 更新最小長度 minLength = minLength == 0 ? (fast - slow + 1) : Math.min(minLength,(fast-slow+1)); slow++; } } fast++; } return minLength; };