leetcode 825. Friends Of Appropriate Ages
leetcode 825. Friends Of Appropriate Ages
原题地址: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 following conditions are true:
age[B] <= 0.5 age[A] + 7*
age[B] > age[A]
age[B] > 100 && age[A] < 100
Otherwise, A will friend request B.
Note that if A requests B, B does not necessarily request A. Also, people will not friend request themselves.
How many total friend requests are made?
Example 1:
Input: [16,16]
Output: 2
Explanation: 2 people friend request each other.
Example 2:
Input: [16,17,18]
Output: 2
Explanation: Friend requests are made 17 -> 16, 18 -> 17.
Example 3:
Input: [20,30,100,110,120]
Output:
Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.
Note:
- 1 <= ages.length <= 20000.
- 1 <= ages[i] <= 120.
python代码
class Solution:def numFriendRequests(self, ages):""":type ages: List[int]:rtype: int"""age = collections.Counter(ages)res=0for A in age:for B in age:if A == B:if B<=0.5*A+7 or B>A or (B>100 and A<100): continueres += (age[A] * (age[A]-1))else:if B<=0.5*A+7 or B>A or (B>100 and A<100): continueres += age[A] * age[B]return res
leetcode 825. Friends Of Appropriate Ages相关推荐
- LeetCode 825 Friends Of Appropriate Ages
LeetCode 825 Friends Of Appropriate Ages 传送门 题目分析 Some people will make friend requests. The list of ...
- 825. Friends Of Appropriate Ages**
825. Friends Of Appropriate Ages** https://leetcode.com/problems/friends-of-appropriate-ages/ 题目描述 S ...
- LeetCode 825 friends-of-appropriate-ages
LeetCode 825 仔细分析一下条件: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && a ...
- 【LeetCode】825. Friends Of Appropriate Ages 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/friends-o ...
- 【Leetcode】825. Friends Of Appropriate Ages
题目地址: https://leetcode.com/problems/friends-of-appropriate-ages/ 给定nnn个人的年龄,当满足以下要求的时候aaa不会给bbb发消息: ...
- LeetCode 825. 适龄的朋友(计数排序+前缀和)
文章目录 1. 题目 2. 解题 1. 题目 人们会互相发送好友请求,现在给定一个包含有他们年龄的数组,ages[i] 表示第 i 个人的年龄. 当满足以下任一条件时,A 不能给 B(A.B不为同一人 ...
- java人员安排表_Java实现 LeetCode 732 我的日程安排表 III(暴力 || 二叉树)
732. 我的日程安排表 III 实现一个 MyCalendar 类来存放你的日程安排,你可以一直添加新的日程安排. MyCalendar 有一个 book(int start, int end)方法 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
原文地址:https://www.cnblogs.com/grandyang/p/4606334.html 终于将LeetCode的大部分题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开 ...
- leetcode每日一题825. 适龄的朋友 快排+双指针
本文目录 leetcode每日一题825. 适龄的朋友 快排+双指针 写在前面 题目 示例 提示 思路 代码实现 执行结果 写在后面 leetcode每日一题825. 适龄的朋友 快排+双指针 写在前 ...
最新文章
- 你也许只使用到了 VS Code 20% 的功能
- 目标检测中的尺度--An Analysis of Scale Invariance in Object Detection – SNIP
- Java进阶篇(一)——接口、继承与多态
- java抽象类实现接口可以不用实现方法
- Java从网络批量读取图片并保存至本网站服务器后再插入文章中
- 5脚12v继电器接线图解_【电器元件002】你真的懂汽车继电器么
- 讨论ALL_ROWS模式和FIRST_ROWS模式
- 下面哪个进制能表述 13*16=244是正确的?)[中国台湾某计算机硬件公司V2010年5月面试题]...
- Sequelize Unknown column 'createdAt' in 'field list'?
- extjs4 store传参使用方法
- Silverlight的依赖属性与附加属性(六)
- iOS:跳转设置界面,权限相关,UIApplicationOpenSettingsURLString的使用
- 热释电传感器三个引脚_热释电传感器电路图大全(六款热释电传感器电路设计原理图详解)...
- 计算机自动关机命令,自动关机命令|电脑自动关机命令|如何设置自动关机 - 电脑自动关机命令详解 - 安全专题...
- php开发工具 知乎,一个微信小程序版知乎实例分享
- 用c语言实现下载文件
- 在线音乐网站毕业设计
- usb转vga转换器
- 创建AccessToken工具类
- 求不规则四边形的面积