#include <leetcode.h>
◆ lastRemaining()
int leetcode::elimination_game::Solution::lastRemaining |
( |
int | n | ) |
|
|
static |
在文件 leetcode.cpp 第 302 行定义.
302 {
303 int num_amount = n;
304 int loop_cnt = 0;
305 int a0 = 1;
306 int d = 1;
307 while(num_amount != 1) {
308
309 if(num_amount % 2 == 1) {
310
311 a0 = a0 + d;
312 } else if(num_amount % 2 == 0) {
313
314 const bool left_to_right = loop_cnt % 2 == 0;
315 if(left_to_right) {
316 a0 = a0 + d;
317 } else {
318 a0 = a0;
319 }
320 }
321 loop_cnt++;
322 d *= 2;
323 num_amount /= 2;
324 }
325 return a0;
326 }
被这些函数引用 leetcode::elimination_game::TEST().
该类的文档由以下文件生成: