字节一面凉经-CrossPlatform

没问八股,问了些项目相关的

+ 如何提高项目并发性可用性
+ 如何支持多个用户的群聊需求
+ 根据项目和专业:国密和国外的算法区别是什么
+ 项目会被中间人攻击吗,如何防止或者实施
+ 平常会怎么使用AI Coding
+ CPP如何管理内存,如何排查和处理内存泄露

手撕

说白了就是求一个有向无环图的拓扑排序,但是鼠鼠代码能力为零直接拉了坨大的来了个 $O(n^2)$ 解。

```cpp
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int list[256];

map<string, vector<string>> components = {
        {"A", {"B", "C"}},
        {"D", {"B", "C"}},
        {"E", {"F", "B"}},
        {"B", {"L", "F"}},
        {"L", {}},
        {"N", {}},
        {"F", {}},
        {"C", {"B"}},
        {"P", {"N"}},
        {"Q", {"P"}}
};

vector<string>  solution(map<string, vector<string>> components) {
    vector<string> res;
    while(1) {
        for(auto &item: components) {
            auto index = int(item.first[0]);
            if(list[index] != -1) continue;
            for(int i = 0; i < item.second.size(); i++) {
                auto index_ = item.second[i][0];
                if(list[int(index_)]==-1) goto end;
            }
            list[index] = 1;
            res.push_back(item.first);
            if (res.size()==components.size()) {
                return res;
            }
            end:
        }
    }
}

int main() {
    for(int i = 0; i < 256; i++) {
        list[i] = -1;
    }
    auto res = solution(components);
    for(auto i : res) {
        cout << i << " ";
    }
}
```

#字节# #暑期实习# #暑期#
全部评论

相关推荐

昨天 19:43
湖北大学 C++
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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