sliding-window

Leetcode 1151. Minimum Swaps to Group All 1's Together.

class Solution {
    public int minSwaps(int[] data) {
        //Sliding window
        int count = 0; 
        for(int i=0; i=count){
                cur -= data[i-count];
            }
            cur += data[i];
            maxCount = Math.max(maxCount,cur);
        }
        return count-maxCount;
    }
}

你可能感兴趣的:(sliding-window)