leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1042.cpp (619B)


0 class Solution {
1 public:
2 vector<int> gardenNoAdj(int n, vector<vector<int>> &paths) {
3 vector<vector<int>> adj(n);
4 for (auto &p : paths) {
5 adj[p[0] - 1].push_back(p[1] - 1);
6 adj[p[1] - 1].push_back(p[0] - 1);
7 }
9 vector<int> res(n);
10 for (int i = 0; i < n; i++) {
11 bitset<5> colors;
13 for (int c : adj[i])
14 colors.set(res[c]);
16 for (int j = 1; j < 5; j++) {
17 if (colors[j]) continue;
18 res[i] = j;
19 break;
20 }
21 }
22 return res;
23 }
24 };