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)};
}

  

最新文章

  1. Shell脚本编程30分钟入门
  2. 1226关于count(*)不走主键索引反而走二级索引
  3. xv6课本翻译之——附录A Pc的硬件
  4. 试试用有限状态机的思路来定义javascript组件
  5. 7 个顶级的 HTML5 Canvas 动画赏析
  6. Windows路由表详解
  7. ucenter同步登陆机制
  8. 读mongoose api 记录
  9. qdoc 写法
  10. COBBLER无人值守安装
  11. Android为TV端助力:intent传递消息
  12. json 函数
  13. Golang开发工具LiteIDE使用方法整理
  14. A + B,末k位不相同
  15. go install and go captcha
  16. Windows Azure Web Site (18) Azure Web App设置MIME
  17. VS2008 开发wince程序设备调试
  18. Python(四)之Python流程控制(if、while、for)
  19. Android学习之SeekBar(控制wav音频的声音)
  20. WPS Word查询某些内容的出现次数

热门文章

  1. 成为数据专家,你只差一个Quick Insights的距离
  2. 网络编程01 &middot; 艺
  3. java ThreadPoolExecutor初探
  4. celery异步任务框架
  5. 时间序列数据库(TSDB)初识与选择(InfluxDB、OpenTSDB、Druid、Elasticsearch对比)
  6. TCP/IP协议族的四个层次
  7. vue+element 表单封成组件(1)
  8. RNN学习笔记(一):长短时记忆网络(LSTM)
  9. Sequence to Sequence Learning with Neural Networks论文阅读
  10. element多层导航菜单