Leetcode 1791. 找出星型图的中心节点 (计算定点的度)

Leetcode 1791. 找出星型图的中心节点 (计算定点的度)

 

class Solution {
public:
    int findCenter(vector<vector<int>>& edges) {
        unordered_map<int, int> degree;
        int max_degree = 0;
        int vertex = 0;
        for (auto edge : edges) {
            degree[edge[0]]++;
            degree[edge[1]]++;
            if (degree[edge[0]] >= max_degree) {
                vertex = edge[0];
                max_degree = degree[edge[0]];
            }
            if (degree[edge[1]] >= max_degree) {
                vertex = edge[1];
                max_degree = degree[edge[1]];
            }
        }
        return vertex;
    }
};

上一篇:关于flutter mac catalina arch: posix_spawnp: ...flutter/bin/cache/artifacts/engine/ios-release/gen_snapshot: Bad CPU type in executable


下一篇:android 学习笔记 1