当前位置:网站首页>Li Kou daily question - day 31 -13 Maximum perimeter of triangle
Li Kou daily question - day 31 -13 Maximum perimeter of triangle
2022-06-29 12:10:00 【Chongyou research Sen】
2022.6.29 Did you brush the questions today ?
subject :
Given by some positive numbers ( Representative length ) Array of components nums , return Consisting of three lengths 、 The area is not zero The maximum circumference of a triangle . If we can't form any triangle with non-zero area , return 0.
analysis :
Given an array , Find the three sides of the triangle that can form the largest perimeter inside , Then return the sum of the three sides .
Ideas : Using sorting intelligence , Look for the last three elements from back to front , As long as the relationship is satisfied, it is the longest side .
analysis :
1. Violent solution
class Solution {
public:
int largestPerimeter(vector<int>& nums) {
sort(nums.begin(), nums.end());
for (auto i = nums.size() - 1; i > 2; i--)
{
if (nums[i - 2] + nums[i - 1] > nums[i])
{
return nums[i - 2] + nums[i - 1] + nums[i];
}
}
return 0;
}
};边栏推荐
- LM07丨细聊期货横截面策略
- Jerry's about TWS pairing mode configuration [chapter]
- 杰理之关于 TWS 交叉配对的配置【篇】
- Serving millions of developers, the first techo day Tencent technology open day released 7 "lightweight" products
- 杰理之关于开机发起回连对耳的位置:【篇】
- 杰理之手动配对方式【篇】
- MMdet的Resnet卷积替换成Ghost卷积组所出现的问题
- ESP8266简介:三种编程方式「建议收藏」
- ShanDong Multi-University Training #3
- AOSP ~ Logcat 持久化
猜你喜欢

Wonderful! Miaoying technology fully implements Zadig to help container construction, and fully embraces kubernetes and Yunyuan

美创入选信通院“业务安全推进计划”首批成员单位

镜像漏洞扫描工具:Trivy

Intelligent trash can (IV) -- raspberry pie Pico realizes ultrasonic ranging (hc-sr04)

Pytoch - distributed communication primitive (with source code)

Pytorch - 分布式通信原语(附源码)

LM07丨细聊期货横截面策略

Pro test! Centos7 deploy PHP + spool

Nature | biosynthetic potential of global marine microbiome
![Jerry's about TWS pairing mode configuration [chapter]](/img/c8/d78e817295169753244299545d9aba.png)
Jerry's about TWS pairing mode configuration [chapter]
随机推荐
MySQL enable slow query
启泰观察:职业精英创业必踩巨坑之 --- 学习效果坑
初次使用 eolink 感受
哈希Hash竞猜游戏系统开发详解技术丨哈希竞猜游戏系统开发方案解析
Sofaregistry source code | data synchronization module analysis
MMdet的Resnet卷积替换成Ghost卷积组所出现的问题
2022 question bank and simulation test for documenter post skills (documenter) operation certificate examination
美创入选信通院“业务安全推进计划”首批成员单位
大家有没有觉得学机械的人很可怕?
[VTK] MFC grid editor based on vtk8.2
ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?
正大期货主账户留4行情软件用的什么?
Jerry's about TWS pairing mode configuration [chapter]
TTChat x Zadig 开源共创 Helm 接入场景,环境治理搞得定!
How to view saved passwords of websites
易快报:我们用 Zadig 实现万次构建部署,聪明运维,释放开发生产力
Codeforces Round #803 (Div. 2)
&4 express框架
& 3 view request message and response message in browser
Numpy的ndarray数组基础