LeetCode-825 适龄的朋友】的更多相关文章

825. 适龄的朋友 人们会互相发送好友请求,现在给定一个包含有他们年龄的数组,ages[i] 表示第 i 个人的年龄. 当满足以下条件时,A 不能给 B(A.B不为同一人)发送好友请求: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 否则,A 可以给 B 发送好友请求. 注意如果 A 向 B 发出了请求,不等于 B 也一定会向 A 发出请求.而且,人们不会给自己发送好…
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C. And we defined a fri…
题目: https://leetcode.com/problems/friend-circles/ There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then…
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person. Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[…
原题链接在这里:https://leetcode.com/problems/friends-of-appropriate-ages/ 题目: Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person. Person A will NOT friend request person B (B != A) if any of the f…
/* 思路就是遍历所有人,对于每一个人,寻找他的好友,找到好友后再找这个好友的好友 ,这样深度优先遍历下去,设置一个flag记录是否已经遍历了这个人. 其实dfs真正有用的是flag这个变量,因为如果m个人最多m个朋友圈,设置后flag后,相同的朋友圈会 检测到flag就会不算数. */ public int findCircleNum(int[][] M) { int m = M.length; if (m==0) return 0; int res = 0; boolean[] flag =…
957. N 天后的牢房 思路: 模拟变换,当N天结合后返回 => 当N非常大的时候,超时 => 一般N很大的时候,这种题目必然存在循环,所以记录找过的状态,一旦出现已经访问过的状态可立即跳出循环. class Solution: def prisonAfterNDays(self, cells, N: int): vis = [] while 1: if not N: return cells if cells in vis: ind = vis.index(cells) break tce…
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如:[Swift]LeetCode156.二叉树的上下颠倒 $ Binary Tree Upside Down 请下拉滚动条查看最新 Weekly Contest!!! Swift LeetCode 目录 | Catalog 序        号 题名Title 难度     Difficulty  两数之…
数组篇 # 题名 刷题 通过率 难度 1 两数之和 C#LeetCode刷题之#1-两数之和(Two Sum) 43.1% 简单 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30.1% 困难 11 盛最多水的容器 C#LeetCode刷题之#11-盛最多水的容器(Container With Most Water) 37.9% 中等 15 三数之和 C#LeetCode刷题之#15-三数…
Given two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are similar. For example, words1 = ["great", "acting", "skills"] and words2 = [&…