滑动窗口-Moving Stones Until Consecutive II
2024-09-06 19:23:26
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)};
}
最新文章
- Shell脚本编程30分钟入门
- 1226关于count(*)不走主键索引反而走二级索引
- xv6课本翻译之——附录A Pc的硬件
- 试试用有限状态机的思路来定义javascript组件
- 7 个顶级的 HTML5 Canvas 动画赏析
- Windows路由表详解
- ucenter同步登陆机制
- 读mongoose api 记录
- qdoc 写法
- COBBLER无人值守安装
- Android为TV端助力:intent传递消息
- json 函数
- Golang开发工具LiteIDE使用方法整理
- A + B,末k位不相同
- go install and go captcha
- Windows Azure Web Site (18) Azure Web App设置MIME
- VS2008 开发wince程序设备调试
- Python(四)之Python流程控制(if、while、for)
- Android学习之SeekBar(控制wav音频的声音)
- WPS Word查询某些内容的出现次数
热门文章
- 成为数据专家,你只差一个Quick Insights的距离
- 网络编程01 ·; 艺
- java ThreadPoolExecutor初探
- celery异步任务框架
- 时间序列数据库(TSDB)初识与选择(InfluxDB、OpenTSDB、Druid、Elasticsearch对比)
- TCP/IP协议族的四个层次
- vue+element 表单封成组件(1)
- RNN学习笔记(一):长短时记忆网络(LSTM)
- Sequence to Sequence Learning with Neural Networks论文阅读
- element多层导航菜单