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