首页 > 其他 > 详细

Influencer Finder

时间:2016-01-24 01:52:13      阅读:143      评论:0      收藏:0      [点我收藏+]

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;
}

 

Influencer Finder

原文:http://www.cnblogs.com/hygeia/p/5154467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!