滑动窗口-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_easy】1033. Moving Stones Until Consecutive
problem 1033. Moving Stones Until Consecutive 参考 1. Leetcode_easy_1033. Moving Stones Until Consecut ...
- [Swift]LeetCode1033. 移动石子直到连续 | Moving Stones Until Consecutive
Three stones are on a number line at positions a, b, and c. Each turn, let's say the stones are curr ...
- 【leetcode】1033. Moving Stones Until Consecutive
题目如下: Three stones are on a number line at positions a, b, and c. Each turn, you pick up a stone at ...
- 【LeetCode】1033. Moving Stones Until Consecutive 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 脑筋急转弯 日期 题目地址:https://leet ...
- leetcode_1033. Moving Stones Until Consecutive
https://leetcode.com/problems/moving-stones-until-consecutive/ 题意:给定3个点,每次从两个端点(位置最小或位置最大)中挑选一个点进行移动 ...
- LeetCode.1033-移动石头直到连续(Moving Stones Until Consecutive)
这是小川的第386次更新,第414篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第247题(顺位题号是1033).在a,b和c位置的数字线上有三块石头.每次,你在一个终点 ...
- [leetcode]346. Moving Average from Data Stream滑动窗口平均值
Given a stream of integers and a window size, calculate the moving average of all integers in the sl ...
- [LeetCode] Sliding Window Maximum 滑动窗口最大值
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
- [LeetCode] 239. Sliding Window Maximum 滑动窗口最大值
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
随机推荐
- 爬虫入门(四):urllib2
主要使用python自带的urllib2进行爬虫实验. 写在前面的蠢事:本来新建了一个urllib2.py便于好认识这是urllib2的实验,结果始终编译不通过,错误错误.不能用Python的关键字( ...
- STL标准库中的容器
容器:顾名思义,我的理解就是把同一种数据类型括起来,作为一捆.如vector<int> ,vector就是个容器,里面全是一个个的int型数据. 容器包括三大块: 顺序型容器: (1)ve ...
- C++走向远洋——59(项目三、图形面积、抽象类)
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- Cenots 7 通过Yum 安装Node.js 报错问题
环境:CentOS Linux release 7.3.1611 (Core) 安装报错信息: [cenots7@localhost ~]$ sudo yum -y install npm Loade ...
- maven包引入问题ClassNotFoundException: org.elasticsearch.client.Cancellable
业务需要,做搜索功能,在springboot聚合项目下,新建了es模块module 但是在引入elasticsearch依赖的时候,出现了问题 引入相应依赖后 <dependency> & ...
- sql数据库在登录异常时 ora-03114:未连接到ORACLE怎么办
关闭SQL数据,重新启动,登录就好,不要用删除,或者其他方法,如果这麽做还是不可以,那么在想其他办法! 我自己就是这麽做的
- H5页面通用头部设置
见到很多人写H5页面都不设置头部,不忍直视,于是整理一篇文章,不定期更新,为了让自己显得专业一点,也为了方便自己复制粘贴 一般来说必须设置项 <!-- 页面编码 --> <meta ...
- Java基础--Java基本数据类型
一.基本数据类型(primitive type) (1)数值型 1.数值型包括整数类型(byte,short,int,long) a.byte :1字节=8bit位 (-128~127) 包装类: ...
- 阿里云上docker部署nginx实现反向代理
简介 需要从镜像仓库找到所需要的nginx版本pull下来.(地址:https://hub.docker.com/) 1.docker pull nginx 1.挂载目录 1.1 获取nginx. ...
- Json转化的三种方式
1. Gson 1.添加依赖 <dependency> <groupId>com.google.code.gson</groupId> <artifactId ...