微信小游戏开发的市场前景与创新策略探讨
699
2022-10-01
[leetcode] 1311. Get Watched Videos by Your Friends
Description
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these candies equally in number to brother and sister. Return the maximum number of kinds of candies the sister could gain.
Example 1:
Input: candies = [1,1,2,2,3,3]Output: 3Explanation:There are three different kinds of candies (1, 2 and 3), and two candies for each kind.Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too. The sister has three different kinds of candies.
Example 2:
Input: candies = [1,1,2,3]Output: 2Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1]. The sister has two different kinds of candies, the brother has only one kind of candies.
Note:
The length of the given array is in range [2, 10,000], and will be even.The number in given array is in range [-100,000, 100,000].
分析
题目的意思是:这道题要找出id的朋友看的视频,并按照频率从小到大输出。思路很直接,构建一个friend图,层序遍历找到id的friend,然后找出其看的video,进行排序就行了。
class Solution: def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]: graph=collections.defaultdict(list) for i,friend in enumerate(friends): for item in friend: graph[i].append(item) i=0 q=collections.deque() q.append(id) s=set() s.add(id) while(i 参考文献 [LeetCode] [Python3] Breadth-first search
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~