the problem:
https://leetcode.com/problems/design-twitter/
my solutiion:
class Twitter:
def __init__(self):
self.tweet_posted = []
self.follow_users = []
def postTweet(self, userId: int, tweetId: int) -> None:
self.tweet_posted.insert(0, [userId, tweetId])
def getNewsFeed(self, userId: int) -> List[int]:
#lst = [ls[1] for ls in self.tweet_posted if ls[0] == userId or list([userId, ls[0]]) in self.follow_users]
lst = []
for i in self.tweet_posted:
if list([userId, i[0]]) in self.follow_users or i[0] == userId:
lst.append(i[1])
return lst
def follow(self, followerId: int, followeeId: int) -> None:
self.follow_users.append([followerId, followeeId])
def unfollow(self, followerId: int, followeeId: int) -> None:
unfollow_user = [followerId, followeeId]
if unfollow_user in self.follow_users:
self.follow_users.remove(unfollow_user)
No error, but wrong answer by leetcode: enter image description here
it seems that my solution should be right since the function getNewsFeed must contain ALL the tweets of the user...
Aucun commentaire:
Enregistrer un commentaire