当前位置:网站首页>力扣------从数组中移除最大值和最小值
力扣------从数组中移除最大值和最小值
2022-06-26 09:33:00 【qq_37760746】

int minimumDeletions(int* nums, int numsSize){
if(numsSize==1){
return 1;
}
int min=100000;
int max=-100000;
int min_index;
int max_index;
for(int a=0;a<numsSize;a++){
if(nums[a]<min){
min=nums[a];
min_index=a;
}
if(nums[a]>max){
max=nums[a];
max_index=a;
}
}
int left=min_index>max_index?min_index+1:max_index+1;
int right=max_index<min_index?numsSize-max_index:numsSize-min_index;
int record=left<right?left:right;
if(max_index<numsSize-1-max_index&&min_index>numsSize-1-min_index){
return record<max_index+1+numsSize-min_index?record:max_index+1+numsSize-min_index;
}
else if(max_index<numsSize-1-max_index&&min_index<numsSize-1-min_index){
return record<(max_index>min_index?max_index+1:min_index+1)?record:max_index>min_index?max_index+1:min_index+1;
}
else if(max_index>numsSize-1-max_index&&min_index<numsSize-1-min_index){
return record<min_index+1+numsSize-max_index?record:min_index+1+numsSize-max_index;
}
else if(max_index>numsSize-1-max_index&&min_index>numsSize-1-min_index){
return record<numsSize-(max_index<min_index?max_index:min_index)?record:numsSize-(max_index<min_index?max_index:min_index);
}
else if(max_index==numsSize-1-max_index){
return record<max_index+1?record:max_index+1;
}
else if(min_index==numsSize-1-min_index){
return record<min_index+1?record:min_index+1;
}
return;
}
边栏推荐
- 首期Techo Day腾讯技术开放日,628等你
- Adding confidence threshold for demo visualization in detectron2
- PHP does not allow images to be uploaded together with data (no longer uploading images before uploading data)
- 2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(2)详解
- Thinking before QPM preparation optimization
- Is it safe to dig up money and make new debts
- Collection object replication
- Pycharm occasionally encounters low disk space
- php提取txt文本存储json数据中的域名
- The shutter tabbar listener is called twice
猜你喜欢

Bbox format conversion (detectron2 function library)

Badge series 4: use of circle Ci

Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)

【pulsar学习】pulsar架构原理

【Sensors 2021】Relation-Based Deep Attention Network with Hybrid Memory for One-Shot Person Re-Id

php提取txt文本存储json数据中的域名

首期Techo Day腾讯技术开放日,628等你

Wechat official account reported error 10003

Upgrade idea to 2021.2 shortcut keys

《單片機原理及應用》——概述
随机推荐
Modify coco evaluation index maxdets=[10,15,20]
thinkphp5手动报错
Detectron2 draw confusion matrix, PR curve and confidence curve
我在中山,到哪里开户比较好?在线开户安全么?
Collection object replication
Badge collection 6:api\_ Use of level
Badge series 8: generate a personalized Badge
Detectron2 save (according to maxap50) model during training_ best. PTH weight
Record a time when the server was taken to mine
How to solve the sample imbalance problem in machine learning?
"One week's work on Analog Electronics" - Basic amplification circuit
OpenCV depthframe -> pointcloud 导致 segmentation fault!
Error importerror: numpy core. multiarray failed to import
【pulsar学习】pulsar架构原理
"One week's solution to analog electricity" - power circuit
【Sensors 2021】Relation-Based Deep Attention Network with Hybrid Memory for One-Shot Person Re-Id
php不让图片跟数据一起上传(不再是先上传图片再上传数据)
【Open5GS】Open5GS安装配置
Pycharm occasionally encounters low disk space
Jetson TX2 installing the SciPy Library