501. Design Twitter
典型的一道看似很复杂,静下来钻进去看,就发现有思路的题目。 考察数据结构的运用,以及要定义一个新的node节点。 Implement a simple twitter. Support the following method: postTweet(user_id, tweet_text) . Post a tweet. getTimeline(user_id) . Get the given user's most recently 10 tweets posted by himself, order by timestamp from most recent to least recent. getNewsFeed(user_id) . Get the given user's most recently 10 tweets in his news feed (posted by his friends and himself). Order by timestamp from most recent to least recent. follow(from_user_id, to_user_id) . from_user_id followed to_user_id. unfollow(from_user_id, to_user_id) . from_user_id unfollowed to to_user_id. Have you met this question in a real interview? Yes Problem Correction Example Example 1: Input: postTweet(1, "LintCode is Good!!!") getNewsFeed(1) getTimeline(1) follow(2, 1) getNewsFeed(2) unfollow(2, 1) getNewsFeed(2) Output: 1 [1] [1] [1] [] Example 2: Input: postTweet(1, "LintCode ...