题解 | #牛群管理系统#

牛群管理系统

https://www.nowcoder.com/practice/7e53cd2fc15847ea91d460496b4c5ddd

#include <type_traits>
class Solution {
  private :
    set<int> st;
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param operations string字符串vector
     * @param args int整型vector<vector<>>
     * @return string字符串vector
     */
    vector<string> manageCows(vector<string>& operations,
                              vector<vector<int> >& args) {
        vector<string> res;                        
        for(int i = 0; i < operations.size(); i++ ){
            string operation = operations[i];
           if (operation == "CowHashSet") {
                res.emplace_back("null");
           }
           if (operation == "add"){
                add(args[i][0]);
                res.emplace_back("null");
           }
           if (operation == "contains"){
                string tmp = contains(args[i][0]) ? "true" : "false";
                res.emplace_back(tmp);
           }
           if (operation == "remove"){
                remove(args[i][0]);
                 res.emplace_back("null");
           }
        }      
        return res;                  
        // write code here
    }
    void add(int value);
    void remove(int value);
    bool contains(int value);

};

void Solution :: add(int value) {
    st.insert(value);
}
void Solution :: remove(int value) {
    st.erase(value);
}
bool Solution :: contains(int value) {
    return st.count(value);
}

全部评论

相关推荐

为啥美团有的笔试可以AI做题啊。。。。我们怎么就不行
碧海蓝涛:因为ai也做不出来
投递美团等公司10个岗位
点赞 评论 收藏
分享
08-04 22:37
桂林学院 Java
花律:看着感觉不差的,实习还是要看点运气,如果不介意可以试试外包实习,我的简历比楼主都差,都可以进
投递BOSS直聘等公司10个岗位
点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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