• Influencer Finder


    public interface InfluencerFinder { 

    /** 
    * Given a matrix of following between N LinkedIn users (with ids from 0 to N-1): 
    * followingMatrix[i][j] == true iff user i is following user j 
    * thus followingMatrix[i][j] doesn't imply followingMatrix[j][i]. 
    * Let's also agree that followingMatrix[i][i] == false 

    * Influencer is a user who is: 
    * - followed by everyone else and 
    * - not following anyone himself 

    * This method should find an Influencer by a given matrix of following, 
    * or return -1 if there is no Influencer in this group. 
    */ 
    int getInfluencer(boolean[][] followingMatrix)

    和Find the celebrity 非常类似

    int getInfluencer(vector<vector<bool> > M) {
        int candidate = 0;
        for(int i=1; i<M.size(); i++)
        {
            if(M[candidate][i] == true || M[i][candidate]==false)
            {
                candidate = i;
            }
        }
        // now verify candidate is indeed an influencer
        for(int j=0; j<M.size(); j++)
        {
            if(j==candidate) continue;
            if(M[candidate][j]==true || M[j][candidate]==false) return -1;
        }
        return candidate;
    }
  • 相关阅读:
    引用传参
    VS2017 用MySQL Connector 链接 MySQL时 getString异常问题
    Matlab学习日记第3天
    Matlab学习日记第2天
    Matlab学习日记第1天
    c#加密解密方法
    DataGridView添加行号
    c#带参数数组链接数据库方法
    2021/5/27
    2021/5/14
  • 原文地址:https://www.cnblogs.com/hygeia/p/5154467.html
Copyright © 2020-2023  润新知