滑动窗口-Moving Stones Until Consecutive II

Posted hyserendipity

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了滑动窗口-Moving Stones Until Consecutive II相关的知识,希望对你有一定的参考价值。

2020-02-20 16:34:16

问题描述:
技术图片

问题求解:

    public int[] numMovesStonesII(int[] stones) {
        int n = stones.length;
        Arrays.sort(stones);
        int min = n;
        int start = 0;
        for (int end = 0; end < n; end++) {
            while (stones[end] - stones[start] + 1 > n) start += 1;
            int curr = end - start + 1;
            if (curr == n - 1 && stones[end] - stones[start] + 1 == n - 1) 
                curr = Math.min(min, 2);
            else 
                min = Math.min(min, n - curr);
        }
        return new int[]{min, Math.max(stones[n - 1] - stones[1] + 2 - n, stones[n - 2] - stones[0] + 2 - n)};
    }

  

 

以上是关于滑动窗口-Moving Stones Until Consecutive II的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode.1033-移动石头直到连续(Moving Stones Until Consecutive)

[leetcode]346. Moving Average from Data Stream滑动窗口平均值

1033. 移动石子直到连续

leetcode 1040. 移动石子直到连续 II(滑动窗口)

(转)滑动平均法滑动平均模型算法(Moving average,MA)

Batch Normalization的正确打开方式