首页 > 其他分享 >leetcode-1024-easy

leetcode-1024-easy

时间:2023-02-27 21:34:09浏览次数:34  
标签:1024 move chooses Alice player game easy Bob leetcode

Divisor Game

Alice and Bob take turns playing a game, with Alice starting first.

Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:

Choosing any x with 0 < x < n and n % x == 0.
Replacing the number n on the chalkboard with n - x.
Also, if a player cannot make a move, they lose the game.

Return true if and only if Alice wins the game, assuming both players play optimally.

Example 1:

Input: n = 2
Output: true
Explanation: Alice chooses 1, and Bob has no more moves.
Example 2:

Input: n = 3
Output: false
Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.

思路一:从直觉上这题应该是和奇偶数有关,直接判断,原理看了官方解答

    public boolean divisorGame(int n) {
        return n % 2 == 0;
    }

标签:1024,move,chooses,Alice,player,game,easy,Bob,leetcode
From: https://www.cnblogs.com/iyiluo/p/17161990.html

相关文章

  • leetcode-1037-easy
    ValidBoomerangGivenanarraypointswherepoints[i]=[xi,yi]representsapointontheX-Yplane,returntrueifthesepointsareaboomerang.Aboomerang......
  • 【LeetCode二叉树#10】从中序与后序遍历序列构造二叉树
    力扣题目链接(opensnewwindow)根据一棵树的中序遍历与后序遍历构造二叉树。注意:你可以假设树中没有重复的元素。例如,给出中序遍历inorder=[9,3,15,20,7]后序遍......
  • #yyds干货盘点# LeetCode面试题:串联所有单词的子串
    1.简述:给定一个字符串 s 和一个字符串数组 words。 words 中所有字符串长度相同。 s 中的串联子串是指一个包含 words 中所有字符串以任意顺序排列连接起来的......
  • LeetCode 79. 单词搜索(/dfs)
    原题解题目约束题解classSolution{public:boolcheck(vector<vector<char>>&board,vector<vector<int>>&visited,inti,intj,string&s,intk)......
  • LeetCode 周赛 334,在算法的世界里反复横跳
    本文已收录到AndroidFamily,技术和职场问题,请关注公众号[彭旭锐]提问。大家好,我是小彭。今天是LeetCode第334场周赛,你参加了吗?这场周赛考察范围比较基础,整体难度......
  • LeetCode 78. 子集(/)
    原题解题目约束题解解法一classSolution{public:vector<int>t;vector<vector<int>>ans;vector<vector<int>>subsets(vector<int>&nums)......
  • #yyds干货盘点# LeetCode面试题:下一个排列
    1.简述:整数数组的一个排列 就是将其所有成员以序列或线性顺序排列。例如,arr=[1,2,3],以下这些都可以视作arr的排列:[1,2,3]、[1,3,2]、[3,1,2]、[2,3,1]。整数数组的......
  • #yyds干货盘点# LeetCode面试题:最长有效括号
    1.简述:给你一个只包含'(' 和')' 的字符串,找出最长有效(格式正确且连续)括号子串的长度。 示例1:输入:s="(()"输出:2解释:最长有效括号子串是"()"示例2:输入:s=")()())"......
  • #yyds干货盘点# LeetCode程序员面试金典:平分正方形
    题目:给定两个正方形及一个二维平面。请找出将这两个正方形分割成两半的一条直线。假设正方形顶边和底边与x轴平行。每个正方形的数据square包含3个数值,正方形的左下顶点坐......
  • #yyds干货盘点# LeetCode程序员面试金典:最佳直线
    题目:给定一个二维平面及平面上的N个点列表Points,其中第i个点的坐标为Points[i]=[Xi,Yi]。请找出一条直线,其通过的点的数目最多。设穿过最多点的直线所穿过的全部点编号从......