当前位置:网站首页>Li Kou daily question - day 31 -1502 Judge whether an arithmetic sequence can be formed
Li Kou daily question - day 31 -1502 Judge whether an arithmetic sequence can be formed
2022-07-01 07:48:00 【Chongyou research Sen】
2022.6.30 Did you brush the questions today ?
subject :
Here's an array of numbers arr .
If it's in a sequence , The difference between any two adjacent terms is always the same constant , Then this sequence is called A sequence of equal differences .
If you can rearrange the array to form an arithmetic sequence , Please return true ; otherwise , return false .
analysis :
Give you an array , Determine whether the array elements form an arithmetic sequence , Be careful , Here the order is required !
Ideas : The reason why the summation formula cannot be used here is that some elements meet the summation but are not equal differences , So we use another property of isochronism
2*a(n2)=a(n1)+a(n3)
That's twice the median = Sum of previous and subsequent items
analysis :
1. Violent solution
class Solution {
public:
bool canMakeArithmeticProgression(vector<int>& arr) {
sort(arr.begin(), arr.end());
for (auto i = 1; i < arr.size()-1 ; i++)
{
if (2 * arr[i] != arr[i - 1] + arr[i + 1])
{
return false;
}
}
return true;
}
};边栏推荐
- [MySQL learning notes 25] SQL statement optimization
- Redisson uses the complete solution - redisson official documents + Notes (Part 1)
- 论文学习——水文时间序列相似性查询的分析与研究
- go通用动态重试机制解决方案的实现与封装
- 2022茶艺师(初级)操作证考试题库及模拟考试
- Kickback -- find the first palindrome character in a group of characters
- atguigu----脚手架--02-使用脚手架(2)
- H5 页面设置了字体的粗细样式,但是在华为手机里微信打开访问样式不生效?
- Custom events of components ①
- 关系数据库如何工作
猜你喜欢

Will Internet talents be scarce in the future? Which technology directions are popular?

2022年茶艺师(中级)复训题库及答案

软件测试方法和技术 - 基础知识概括

2022广东省安全员A证第三批(主要负责人)特种作业证考试题库模拟考试平台操作

Huawei modelarts training alexnet model

The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?

The programmer of Beipiao posted a post for help late at night: I am lonely when my girlfriend is gone

【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)

Array: question brushing record

redisson使用全解——redisson官方文檔+注釋(上篇)
随机推荐
[MySQL learning notes 25] SQL statement optimization
Apple账号密码自动填充
ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?
Saving db4i depth camera pictures with MATLAB
JAX的深度学习和科学计算
2022 mobile crane driver test exercises and online simulation test
The programmer of Beipiao posted a post for help late at night: I am lonely when my girlfriend is gone
Apple account password auto fill
MySQL and redis consistency solution
Minecraft 1.16.5模组开发(五十一) 方块实体 (Tile Entity)
熱烈祝賀五行和合酒成功掛牌
【mysql学习笔记28】存储函数
[MySQL learning notes 28] storage function
Array: question brushing record
【R语言】年龄性别频数匹配 挑选样本 病例对照研究,对年龄性别进行频数匹配
redisson使用全解——redisson官方文档+注释(上篇)
Oracle create auto increment ID
[MySQL learning notes27] stored procedure
2022制冷与空调设备运行操作国家题库模拟考试平台操作
Software testing methods and techniques - overview of basic knowledge