题解 | 参议院投票

参议院投票

https://www.nowcoder.com/practice/f334a81b22654efc8d7a67e31f60de50

#include <queue>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 求出最终获胜帮派的名称
     * @param s string字符串 
     * @return string字符串
     */
    string predictVictory(string s) {
        int r1=0,d1=0;
        for(auto i:s) i=='R'?r1++:d1++;
        return r1>d1?"Red":"Dark";
    }
};

我发现只要比较D和R的个数就行了

全部评论
并非,两个成员数量相等时不起效。如“DR”和“RD”输出结果会相同
点赞 回复 分享
发布于 02-01 20:17 广东

相关推荐

评论
4
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务