当前位置:网站首页>1019. the next larger node in the linked list
1019. the next larger node in the linked list
2022-06-09 10:11:00 【Mr Gao】
1019. The next node in the linked list
Given a length of n The linked list of head
For each node in the list , Find the next one Larger nodes Value . in other words , For each node , Find the value of the first node next to it , The value of this node Strictly greater than It's worth .
Returns an array of integers answer , among answer[i] It's No i Nodes ( from 1 Start ) The value of the next larger node . If the first i One node does not have the next larger node , Set up answer[i] = 0
Input :head = [2,1,5]
Output :[5,5,0]
Input :head = [2,7,4,3,5]
Output :[7,0,5,5,0]
The solution code is as follows :
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */
/** * Note: The returned array must be malloced, assume caller calls free(). */
struct ListNode* f(struct ListNode* p,int val){
while(p){
if(p->val>val){
return p;
}
p=p->next;;
}
return NULL;
}
int* nextLargerNodes(struct ListNode* head, int* returnSize){
int r=0;
int max=0;
struct ListNode* p=head;
struct ListNode* s;
int len=0;
while(p){
p=p->next;
len++;
}
* returnSize=len;
int *arr=(int *)malloc(sizeof(int)*len);
len=0;
while(head){
s=f(head->next,head->val);
if(s){
arr[len++]=s->val;
}
else{
arr[len++]=0;
}
head=head->next;
}
return arr;
}
边栏推荐
- Sword finger offer 19 Regular expression matching recursion
- [leetcode] [Niuke] brush questions on binary tree
- [technology, business and management] drama learning and Entrepreneurship: Silicon Valley season 5 Episode 1-3
- 【实战技能】Google I/O 2022大会AI/ML给开发者的启发
- [figure machine learning] heuristic link prediction method
- MSF使用小技巧
- [FAQ for novices on the road] about Internet of things design
- Redis info command memory information description
- 8、 Vertices, extremum points and basic feasible solutions of linear programming
- 电池充放电设备招投标解决方案
猜你喜欢

Machine learning notes - Interpretation of u-net papers

Openstack explanation (18) -- Nova service startup and service creation

openstack详解(十五)——openstack Nova节点基本原理

MSF针对FTP的后门攻击危害
![[technology, business and management] drama learning and Entrepreneurship: Silicon Valley Season 6 Episode 6-7](/img/4b/fb5233352da446f8ee5892832da836.png)
[technology, business and management] drama learning and Entrepreneurship: Silicon Valley Season 6 Episode 6-7

1019. 链表中的下一个更大节点

用户目录一站式指南
![[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

机器学习笔记 - 什么是BLEU分数?

Redis集群实例内存使用率飙升排查
随机推荐
长安链ChainMaker多机环境
MSF tips
Openstack explanation (12) -- glance installation and Preliminary Configuration
Machine learning notes - create confusion matrix using scikit learn
Extensions attribute of TS generics
MSF实战——ms17-010漏洞的危害
登出成功处理器
机器学习笔记 - R语言学习入门系列一
Kubernetes第七篇:Pod进阶、Controller进阶、Resource和Dashboard
【科技、商业和管理】看剧学创业:《硅谷》第五季第7-8集
机器学习笔记 - Transformer/Attention论文解读
There is no network for the computer web browser, but QQ and wechat can log in to solve the browser network problem
MSF module search details
Kubernetes第七篇:Pod進階、Controller進階、Resource和Dashboard
[recommendation system] user based collaborative filtering
The role of graphic edge detection in digital image processing in image understanding
106. 从中序与后序遍历序列构造二叉树
Introduction à l'AC du tissu, installation, utilisation
MSF基于SSH协议的信息收集
机器学习笔记 - 使用Keras和深度学习进行乳腺癌分类