当前位置:网站首页>2130. maximum twin sum of linked list
2130. maximum twin sum of linked list
2022-06-11 08:56:00 【Drag is me】
leetcode Force button to brush questions and punch in
* subject :2130. The largest twins in the linked list are
describe : In a size of n And n by even numbers In the linked list , about 0 <= i <= (n / 2) - 1 Of i , The first i Nodes ( Subscript from 0 Start ) The twin node of is (n-1-i) Nodes .
For example ,n = 4 Then the node 0 Is the node 3 Twin nodes of , node 1 Is the node 2 Twin nodes of . This is the length of n = 4 All twin nodes in the linked list .
Twin sum It is defined as the sum of the values of a node and its twin nodes .
Give you the head node of a linked list with an even length head , Please return to the linked list The largest twins and .
Their thinking
1、 The array stores the values of the linked list nodes ;
2、 Compare the maximum twins and ;
Source code ##
class Solution {
public:
int pairSum(ListNode* head) {
vector<int>v;
while (head) {
v.emplace_back(head->val);
head = head->next;
}
int sum = 0, ans = 0, n = v.size();
for (int i = 0; i < n / 2; ++i) {
sum = v[i] + v[n - 1 - i];
ans = max(ans, sum);
}
return ans;
}
};
边栏推荐
- 86. separate linked list
- Screaming Frog Log File Analyser 中文版安装教程
- 1721. 交换链表中的节点
- Display DIN 4102-1 Class B1 fire test requirements
- Matlab学习7-图像处理之线性平滑滤波
- leveldb简单使用样例
- What are precompiled, compiled, assembled, linked, static and dynamic libraries
- 682. 棒球比赛
- Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup
- 445. 两数相加 II
猜你喜欢

Sword finger offer 40 Minimum number of K

c语言打印心形

领导让我重写测试代码,我也要照办嘛?

Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup

typescript高阶特性一 —— 合并类型(&)

端口占用问题,10000端口

面试官问了四个问题,总结了4个经验

Sword finger offer 10- ii Frog jumping on steps

Matlab学习9-图像处理之非线性锐化滤波

Textview text size auto fit and textview margin removal
随机推荐
leetcode - 460. LFU 缓存
Sword finger offer 51 Reverse pair in array
Screaming Frog Log File Analyser 中文版安装教程
2022 Niuke winter vacation 3
Sword finger offer 06 Print linked list from end to end
Matlab learning 9- nonlinear sharpening filter for image processing
[node] NPM part
leetcode - 460. LFU cache
File system check of the root filesystem failed
完整的ES6面试题
EN45545-2 R26垂直燃烧测试介绍
【Image Processing】空间域图像增强
预编译,编译,汇编,链接,静态库,动态库都是什么
What is the process of en 1101 flammability test for curtains?
What are the requirements of the drive housing UL 2043?
Vagrant mounting pit
Flutter开发日志——路由管理
For in / for of / foreach loop
Can not connect to local MySQL server through socket ‘/tmp/mysql. sock (2)‘
Complete ES6 questions