算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !
今天和大家聊的问题叫做 二级关注者,我们先来看题面:
https://leetcode.cn/problems/second-degree-follower/
解题
第一个表的关注者是第二个表的被关注者,对第二个表的关注者计数
方法一:
select followee as follower,count(distinct follower) as num
from follow
where followee in (select follower from follow)
group by followee
方法二:
select a.followee as follower,count(distinct a.follower) as num
from follow a
join follow b on a.followee = b.follower
group by a.followee
上期推文:
LeetCode刷题实战602:好友申请 II :谁有最多的好友