https://leetcode.com/problems/elimination-game/

// 一行代码就可以,不过原理有些复杂
// https://discuss.leetcode.com/topic/58042/c-1-line-solution-with-explanation
// return n == 1 ? 1 : 2 * (1 + n / 2 - lastRemaining(n / 2));
// https://discuss.leetcode.com/topic/59293/easiest-solution-o-logn-with-explanation public class Solution {
public int lastRemaining(int n) { boolean isLeft = true;
int left = n;
int step = 1;
int head = 1; while (left != 1) {
if (isLeft || left % 2 == 1) {
head += step;
}
step *= 2;
left /= 2;
isLeft = !isLeft;
}
return head; }
}

最新文章

  1. 理解 Neutorn LBaaS - 每天5分钟玩转 OpenStack(120)
  2. NET Core-学习笔记(一)
  3. 生产uuid
  4. 1027mysqlbinlog工具日志恢复
  5. svn local obstruction, incoming add upon merge
  6. rtx信息泄漏利结合弱口令导致被批量社工思路
  7. 关于AutoComplete整合
  8. iOS语音合成
  9. RHEL-resolv.conf文件修改后重启被还原
  10. JavaScript 【跨浏览器处理XML,做个兼容】
  11. Linux进程和线程的比較
  12. 必须掌握的JavaScript基本知识
  13. HtmlAgilityPack实战代码
  14. Facebook开源的基于SQL的操作系统检测和监控框架:osquery Table详解
  15. H5如何解监听页面退出需求???
  16. webRTC中音频相关的netEQ(三):存取包和延时计算
  17. 多个微信小程序一个服务端架构
  18. 总结的U3D面试题
  19. 在docker hub,用github的dockerfile自动生成docker镜像
  20. [LeetCode] Read N Characters Given Read4 I & II

热门文章

  1. Java异常处理中的恢复模型
  2. Linux-CentOs7-svn安装及钩子配置
  3. 选择 React Native 的理由
  4. python使用web.py开发httpserver,解决post请求跨域问题
  5. python opencv3 圆检测
  6. pycharm 激活相关
  7. Codeforces Round #489 (Div. 2)
  8. BZOJ.4919.[Lydsy1706月赛]大根堆(线段树合并/启发式合并)
  9. Wannafly挑战赛22游记
  10. bzoj 2178