当前位置:网站首页>2289. arrange arrays in non decreasing order
2289. arrange arrays in non decreasing order
2022-06-09 10:11:00 【Mr Gao】
2289. Make the array in non decreasing order
I'll give you a subscript from 0 The starting array of integers nums . In one step , Remove all satisfaction nums[i - 1] > nums[i] Of nums[i] , among 0 < i < nums.length .
Repeat steps , until nums Turn into The decreasing Array , Returns the number of operations to be performed .
Example 1:
Input :nums = [5,3,4,4,7,3,6,11,8,5,11]
Output :3
explain : Perform the following steps :
- step 1 :[5,3,4,4,7,3,6,11,8,5,11] Turn into [5,4,4,7,6,11,11]
- step 2 :[5,4,4,7,6,11,11] Turn into [5,4,7,11,11]
- step 3 :[5,4,7,11,11] Turn into [5,7,11,11]
[5,7,11,11] It is a group of non decreasing numbers , therefore , return 3 .
Example 2:
Input :nums = [4,5,7,7,13]
Output :0
explain :nums It is already a non decreasing group , therefore , return 0 .
int totalSteps(int* nums, int numsSize){
int pre=nums[0];
int i;
int num=0;
int size=numsSize;
int r;
while(1){
int p=1;
r=0;
for(i=1;i<size;i++){
if(nums[i]<nums[i-1]){
r=1;
continue;
}
else{
nums[p++]=nums[i];
}
}
num++;
printf("%d ",p);
if(r==0){
break;
}
size=p;
}
return num-1;
}
边栏推荐
- 用好条件访问,远程办公更安全高效
- 1340. 跳跃游戏 V-动态规划加dfs
- With good conditional access, remote office is more secure and efficient
- fabric-ca介紹,安裝,使用
- [probability theory] correlation calculation between variables
- 华泰证券是安全的吗
- Openstack explanation (16) -- openstack Nova installation and database configuration
- 面试题 01.06. 字符串压缩
- openstack详解(十七)——openstack Nova其他配置
- 978. 最长湍流子数组
猜你喜欢
![[technology, business and management] drama learning and Entrepreneurship: Silicon Valley Season 6 Episode 3-5](/img/67/65df8f06d9019c3fc2f089ea52b541.png)
[technology, business and management] drama learning and Entrepreneurship: Silicon Valley Season 6 Episode 3-5

MSF practice - harm of ms17-010 vulnerability

MSF SSH protocol based information collection

【科技、商業和管理】看劇學創業:《矽穀》第五季第4-6集

MSF information collection based on TCP protocol
![[technology, business and management] drama learning and Entrepreneurship: Silicon Valley season 5 Episode 4-6](/img/3b/32ef523daaa9a3d0a3805a6527c8e8.png)
[technology, business and management] drama learning and Entrepreneurship: Silicon Valley season 5 Episode 4-6

【genius_platform软件平台开发】第一万零一讲:电力项目dz产品windows环境vs2017编译遇到的报错汇总

Openstack explanation (XV) -- basic principle of openstack Nova node

MicroNet:以极低的 FLOP 实现图像识别

Machine learning notes - Interpretation of u-net papers
随机推荐
16. 最接近的三数之和-快速排序加双指针法
Blazor University (27)路由 —— 检测导航事件
【genius_platform软件平台开发】第三十七讲:网卡混杂模式和原始套接字
面试题 10.03. 搜索旋转数组
Openstack explanation (XX) -- neutron node principle
Troubleshooting of soaring memory utilization of redis cluster instances
openstack详解(十二)——Glance安装与初步配置
31. 下一个排列
Interview question 01.06 String compression
Terrain learning summary (6) -- terrain practice based on Alibaba cloud platform
MSF SNMP based information collection
1324. 竖直打印单词-力扣双百代码
Machine learning notes - create confusion matrix using scikit learn
openstack详解(十八)——Nova服务启动与服务创建
MicroNet:以极低的 FLOP 实现图像识别
自定义权限校验方法
当你孤独,抑郁,焦虑的时候......请记得,还有风雨
ISCC2022 擂台misc
MSF基于SSH协议的信息收集
openstack详解(十四)——Glance Keystone注册