In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "golang leetcode skills how to solve moments problems", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "golang leetcode skills how to solve moments problems" this article.
There are N students in the class. Some of them are friends and some are not. Their friendship is transitive. If we know that An is a friend of B and B is a friend of C, then we can think that An is also a friend of C. The so-called moments refers to the collection of all friends.
Given a matrix M of N * N, it represents the friend relationship between the middle school students in the class. If M [I] [j] = 1, it means that the I and j students are known to be friends with each other, otherwise they do not know. You must output the total number of known moments among all the students.
Example 1:
Enter:
[[1,1,0]
[1,1,0]
[0,0,1]]
Output: 2
Explanation: it is known that student 0 and student 1 are friends with each other, and they are in a circle of friends.
The second student himself is in a circle of friends. So return 2.
Example 2:
Enter:
[[1,1,0]
[1,1,1]
[0,1,1]]
Output: 1
Explanation: it is known that student 0 and student 1 are friends with each other, and student 1 and student 2 are friends with each other, so student 0 and student 2 are also friends, so the three of them are in a circle of friends and return 1.
Note:
N is within the range of [1200].
For all students, M [I] [I] = 1.
If there is M [I] [j] = 1, then M [j] [I] = 1.
Ideas for solving the problem:
1, because a friend's friend is still a friend, the first thing to think of is depth-first traversal.
The above is all the contents of this article entitled "how to solve moments problems with golang leetcode skills". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.