[LeetCode]390. Elimination Game
来源:互联网 发布:hive sql insert into 编辑:程序博客网 时间:2024/05/29 21:16
https://leetcode.com/problems/elimination-game/#/description
从左往右和从右往左交替删除数字,求最后留下的数字是什么
step是head移动步长,当是从左向右 或 (从右向左 && 剩余数字数目为奇数)head右移step位
public class Solution { public int lastRemaining(int n) { boolean left = true; int remain = n; int head = 1; int step = 1; while (remain > 1) { if (left || remain % 2 == 1) { head = head + step; } step *= 2; remain /= 2; left = !left; } return head; }}
0 0
- [LeetCode] 390. Elimination Game
- LeetCode 390. Elimination Game
- 【LeetCode】390. Elimination Game
- 【LeetCode】 390. Elimination Game
- LeetCode 390. Elimination Game
- [leetcode]390. Elimination Game
- [LeetCode]390. Elimination Game
- LeetCode 390. Elimination Game
- [leetcode] 390. Elimination Game
- leetcode 390. Elimination Game
- leetcode 390. Elimination Game
- Leetcode 390. Elimination Game
- LeetCode—390. Elimination Game
- [Leetcode] 390. Elimination Game 解题报告
- leetcode 390. Elimination Game 消除游戏
- 390. Elimination Game
- 390. Elimination Game
- 390. Elimination Game
- 最近在研究安卓的我网络监听(BroadcastReiver)
- java 读取csv文件
- 非对称加密和对称加密、ASE加密、openssl方法加密。
- Google Blockly安卓原生图形化编程详解
- GitLab搭建-使用清华大学开源软件镜像站
- [LeetCode]390. Elimination Game
- 简单MSSQLServer语句
- openyoudao
- 数据文件和日志文件的批量迁移脚本
- Xutils3向服务器发送json,并得到返回的json数据
- Chrome报表单提交错误,Form submission canceled because the form is not connected
- 谈谈行内元素和块元素的区别和居中问题
- sublime Text3技巧
- git clone代码提示需要输入密码