当前位置:网站首页>1299. replace each element with the largest element on the right
1299. replace each element with the largest element on the right
2022-06-22 03:32:00 【Mr Gao】
1299. Replace each element with the largest element on the right
Give you an array arr , Please replace each element with the largest one on the right , If it's the last element , use -1 Replace .
After all the replacement operations have been completed , Please return this array .
Example 1:
Input :arr = [17,18,5,4,6,1]
Output :[18,6,6,6,1,-1]
explain :
- Subscript 0 The elements of --> The largest element on the right is the subscript 1 The elements of (18)
- Subscript 1 The elements of --> The largest element on the right is the subscript 4 The elements of (6)
- Subscript 2 The elements of --> The largest element on the right is the subscript 4 The elements of (6)
- Subscript 3 The elements of --> The largest element on the right is the subscript 4 The elements of (6)
- Subscript 4 The elements of --> The largest element on the right is the subscript 5 The elements of (1)
- Subscript 5 The elements of --> There are no other elements on the right , Replace with -1
Example 2:
Input :arr = [400]
Output :[-1]
explain : Subscript 0 There are no other elements to the right of the element .
The solution code is as follows :
/** * Note: The returned array must be malloced, assume caller calls free(). */
int* replaceElements(int* arr, int arrSize, int* returnSize){
int max[arrSize];
int i=0;
int maxt=arr[arrSize-1];
for(i=arrSize-1;i>=0;i--){
if(arr[i]>maxt){
max[i]=arr[i];
maxt=arr[i];
}
else{
max[i]=maxt;
}
}
for(i=0;i<arrSize-1;i++){
arr[i]=max[i+1];
}
arr[i]=-1;
*returnSize=arrSize;
return arr;
}
边栏推荐
- TX2 mirror source settings
- Factory mode
- Join等待多个线程的同步结果
- 【NVMe2.0b 5】NVM Subsystem
- 策略模式
- A component required a bean of type 'com.example.demo3.service.UserServiceImp' that could not be fou
- [microservices | Nacos] quickly realize the configuration center function of Nacos, and complete configuration update and version iteration
- AtCoder Regular Contest 142
- 剑指 Offer 68 - II. 二叉树的最近公共祖先
- Deep learning final review
猜你喜欢
![[nvme2.0b 9] controller initialization process](/img/70/536b2c850c611d5d0c013586d4c2d5.png)
[nvme2.0b 9] controller initialization process

调度功能:splunk-operator-controller-manager

eu5,eu7,ex3,ex5安装第三方app

Factory mode

Shelling of ESP law of reverse crackme

Splunk: Auto load Balanced TCP Output issue
![[nvme2.0b 5] sous - système nvm](/img/4f/e60e62a04e617b2e7858494917f390.png)
[nvme2.0b 5] sous - système nvm

2022 low voltage electrician test question simulation test question bank and answers

Irregular layout of table label

告警日志中出现ORA-48132 ORA-48170
随机推荐
Golang standard library time
TX2 mirror source settings
zombie进程与orphan进程
R data analysis: significance and practice of calibration curve and DCA curve in clinical prediction model
[nvme2.0b 12] NVM capacity model
3de 机器人吸盘抓box
【NVMe2.0b 8】NVMe 队列仲裁机制
Splunk: Auto load Balanced TCP Output issue
我们如何解决了RealSense偏色问题?
MySQL index creation, optimization analysis and index optimization
Policy mode
3de 保存到收藏夹
powerdesigner CDM中联系理解
Selenium entry level project - Doudou quiz
Implementation of synchronization and atomic operation by mutex mutex in golang concurrent programming
Explanation of atomic operation in golang concurrent programming
告警日志中出现ORA-48132 ORA-48170
【NVMe2.0b 9】控制器初始化过程
达梦数据库客户端屏蔽sql关键字
replacement has 2 rows, data has 0, 解决R语言如何动态生成dataframe