当前位置:网站首页>Leetcode sword finger offer 22 The penultimate node in the linked list
Leetcode sword finger offer 22 The penultimate node in the linked list
2022-04-22 04:41:00 【Twilight rain forest bell】
The basic idea :
Enter a linked list , Output the last number in the list k Nodes . In order to conform to the habits of most people , From 1 Start counting , That is, the tail node of the list is the last 1 Nodes .
for example , A list has 6 Nodes , Start from the beginning , Their values, in turn, are 1、2、3、4、5、6. The last of the list 3 Each node has a value of 4 The node of .
No idea , Just mark it with a pointer ;
Specific code :
class Solution {
public:
vector<int> exchange(vector<int>& nums) {
int l=0;
for(int i=0;i<nums.size();i++){
if(nums[i]%2==1){
swap(nums[i], nums[l]);
l++;
}
}
return nums;
}
};
版权声明
本文为[Twilight rain forest bell]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220438342764.html
边栏推荐
- Linked list Part III
- Target detection - lightweight network (as of April 21, 2022)
- 如何在 Bash 中将字符串计算为数字?
- DHCP protocol workflow
- Will the expired data of redis be deleted immediately?
- H7-tool releases firmware v2 15. For offline recording, the full series SPI flash of Renesas, Hetai and is25wp are added (2022-04-14)
- Objectmapper, stop being new like a second product
- 22.4.21学习感悟
- Bi set - SSM campus second-hand book sales system + thesis
- 论文阅读 (47):DTFD-MIL: Double-Tier Feature Distillation Multiple Instance Learning for Histopathology..
猜你喜欢
![[concurrent programming 043] how to solve the problems of CAS and ABA?](/img/bd/8638aa75d7d3b237d792a201e68c0f.png)
[concurrent programming 043] how to solve the problems of CAS and ABA?

Solution to Chinese translation of GoLand (in case of failure to download plug-ins)

How much do you know about the testing methods of software testing?

AT32 MCU Audio 24bit例程

The website is linked to the gambling dark chain

SCI论文写作--IEEE期刊的Word模板(LaTeX也有)

2022G2电站锅炉司炉操作证考试题库及在线模拟考试

不同品牌设备如何兼容实现互联?一文教你看懂

目标检测--轻量级网络(截至2022-04-21)

6_ Data analysis modeling
随机推荐
The website is linked to the gambling dark chain
一文告诉你分析即服务(AaaS)到底是什么
rpc error: code = Unavailable desc = error reading from server: EOF
6_ Data analysis modeling
10. Libevent receives and processes server messages
13. Bufferevent receives and sends data
Unity simple UI prefix tree red dot system
手机软件(App)测试主要有哪些方面?
12.libevent循环函数和退出测试
MUI-弹出菜单
更换vscode解释器
15.bufferevent客户端测试连接服务器
22.4.21 learning comprehension
2022T电梯修理考试试题及在线模拟考试
JVM shorthand
[concurrent programming 046] for the synchronization method, how does the processor realize atomic operation?
requires XXX>=YYY, but you‘ll have XXXX=ZZZ which is incompatible
目标检测--轻量级网络(截至2022-04-21)
安装opencv时遇到的报错
SCI paper writing -- word template of IEEE Journal (also available in latex)