File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ int global_id; // 全局变量,记录所有推文的时间顺序。
6
6
unordered_map<int,vector<pair<int,int>>>Tweets; // 记录每个用户发推的global_id和tweetID。
7
7
8
8
在getNewsFeed时,遍历所有好友的推文记录,寻找最近的10个。
9
- 基本思路是构造一个数据结构news,每次放进一个推文,news能够自动保持根据global_id保持有序。什么数据结构能实现这个功能呢?有两个方案:priority_queue,或者有序map(set亦可)。考虑到map里的元素已经是pair,而map的自动排序就是依照pair的第一个key从小到大 ,在这里更为方便。
9
+ 基本思路是构造一个数据结构news,每次放进一个推文,news能够自动保持根据global_id保持有序。什么数据结构能实现这个功能呢?有两个方案:priority_queue,或者有序set。考虑到set里的元素已经是pair,并且其自动排序就是依照pair的第一个key从小到大 ,在这里更为方便。
10
10
``` cpp
11
- map< int ,int >news; // 第一个key是推文的global_id,第二个才是其tweetId
11
+ set<pair< int ,int > >news; // 第一个key是推文的global_id,第二个才是其tweetId
12
12
for (auto i:friends[userId]) // 遍历所有userId的好友
13
13
{
14
14
for (int j=tweets[ i] .size()-1; j>=0; j--) //遍历该好友的所有推文,从最近的开始
You can’t perform that action at this time.
0 commit comments