yyyyye 一行代码写完收工 class Solution { public: string losingPlayer(int x, int y) { return min(x, y / 4) & 1 ? "Alice" : "Bob"; } };
If_you_love yyyyye 虽然我很唐,但是打都打了 class Solution { public: string losingPlayer(int x, int y) { string name[2]={"Alice","Bob"}; int a=1; while (1) { if(x>=1&&y>=4) { x-=1; y-=4; a+=1; } else { return name[a&1]; } } } }; 时间复杂度:O(1);空间复杂度:O(1);
xxingyu /* * @lc app=leetcode.cn id=3222 lang=cpp * * [3222] 求出硬币游戏的赢家 */ #include <bits/stdc++.h> using namespace std; // @lc code=start class Solution { public: string losingPlayer(int x, int y) { return min(x, y / 4) % 2 ? "Alice" : "Bob"; } }; // @lc code=end
wszyh 75的硬币只需要一个10的硬币每人要4个 判断哪份可按量分配的更少 少的那份如果余2为0Bob赢,如果余2为1Alice赢 class Solution { public: string losingPlayer(int x, int y) { int minn=min(x/1,y/4); if(minn%2) return "Alice"; return "Bob"; } };`
Koarz class Solution { public: string losingPlayer(int x, int y) { int a = y / 4; if (x >= a) { return a & 1 ? "Alice" : "Bob"; } return x & 1 ? "Alice" : "Bob"; } };
Zero_canyon class Solution { public: string losingPlayer(int x, int y) { int yy = y/4; if(x>=yy && yy&1 || x<yy && x&1) return "Alice"; else return "Bob"; } };
ssssshi 我爱水题 class Solution { public: string losingPlayer(int x, int y) { int t; while(x>=0&&y>=0) { t=(t+1)%2; x-=1; y-=4; } if(t==0) { return "Alice"; } return "Bob"; } };
Godwit 这道题乍一看挺复杂的,实际上非常简单,因为每个人拿硬币的方式只有75+4*10这一种 class Solution { public: string losingPlayer(int x, int y) { string s="Alice"; int f=0; while(x>=0&&y>=0){ x-=1; y-=4; f++; } if (f%2) s="Bob"; return s; } };
Future 加训位运算 public: string losingPlayer(int x, int y) { if(x>y/4) { x=y/4; } return x%2?"Alice":"Bob"; } };
RiVER class Solution { public: string losingPlayer(int x, int y) { int res = 0; while(x >= 1 && y >= 4) { res++; x-=1; y-=4; } if(res%2==1) return "Alice"; else return "Bob"; } };
发表情包召唤 115块钱只有1张754张100一种拿法,被自己刚开始写的时候唐到了 public: string losingPlayer(int x, int y) { int s=0; while(1) { if(x>=1&&y>=4) { s++;x-=1;y-=4; } else break; } if(s%2==1)return "Alice"; else return "Bob"; } };```
xujingyuan 我这方法是人和不是人的都能理解,用循环一个一个搜索,计数,看计数器停的位置,就两个人很容易判断。 char* losingPlayer(int x, int y) { int cnt=0; for(int i=0;i<=x;i++) { for(int j=0;j<=y;j++) { if(i*75+j*10==115) { cnt++; x-=i; y-=j; i=0; j=0; } } } if(cnt%2)return "Alice"; else return "Bob"; }
ygxdsh string losingPlayer(int x, int y) { int ans=min(x,y/4); if(ans%2) return "Alice"; return "Bob"; }
Makise_ 好久没写题了,写个水题吧 public: string losingPlayer(int x, int y) { if ((min(x,y/4))%2) return "Alice"; else return "Bob"; } }; 思路很简单,因为都是1*75+4*10这一种方法取硬币,所以只需要看75和10的硬币数量就好了,由于取硬币有顺序,所以对2取余,余数为1就是到爱丽丝,为0就是鲍勃