LeetCode-19-Remove Nth Node From End of List(C语言实现)
来源:互联网 发布:网络带给我们的好处 编辑:程序博客网 时间:2024/06/16 14:20
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
int i;
struct ListNode *p, *q, *tmp;
p = head;
q = head;
for(i = 0; i < n; ++i)
q = q -> next;
if(q == NULL)
{
tmp = p;
p = p -> next;
free(tmp);
return p;
}
while(q -> next != NULL)
{
p = p-> next;
q = q -> next;
}
tmp = p -> next;
p -> next = tmp -> next;
free(tmp);
return head;
}
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
int i;
struct ListNode *p, *q, *tmp;
p = head;
q = head;
for(i = 0; i < n; ++i)
q = q -> next;
if(q == NULL)
{
tmp = p;
p = p -> next;
free(tmp);
return p;
}
while(q -> next != NULL)
{
p = p-> next;
q = q -> next;
}
tmp = p -> next;
p -> next = tmp -> next;
free(tmp);
return head;
}
阅读全文
0 0
- Leetcode c语言-Remove Nth Node From End of List
- LeetCode-19-Remove Nth Node From End of List(C语言实现)
- 【LeetCode-19】Remove Nth Node From End of List(C++)
- [C语言][LeetCode][19]Remove Nth Node From End of List
- [C++]LeetCode: 4 Remove Nth Node From End of List
- [leetcode-]Remove Nth Node From End of List(C)
- 【C++】【LeetCode】19. Remove Nth Node From End of List
- [Leetcode]LeetCode 19:Remove Nth Node From End of List
- Leetcode 19 Remove Nth Node From End of List
- LeetCode 19: Remove Nth Node From End of List
- [Leetcode 19, Easy] Remove Nth Node From End of List
- LeetCode(19) Remove Nth Node From End of List
- [LeetCode 19] Remove Nth Node From End of List Solutions
- leetcode 19 Remove Nth Node From End of List
- Leetcode【19】:Remove Nth Node From End of List
- [leetcode 19] Remove Nth Node From End of List
- [Leetcode] 19 - Remove Nth Node From End of List
- LeetCode | #19 Remove Nth Node From End of List
- 数据结构实验之查找六:顺序查找
- [LOJ6257][CodePlus 2017 12 月赛]可做题2-矩阵快速幂-乘法逆元
- Lua、Luajit、Python、Node.js和Java性能测试对比
- Tampermonkey(油猴子)插件安装、使用
- 使用 gprof 监测程序性能 (1)
- LeetCode-19-Remove Nth Node From End of List(C语言实现)
- Python scrapy 爬取安软市场
- c++实现二叉树的先序遍历,中序遍历,后序遍历(递归方法)
- java 开发模式之七 : 适配器模式
- LEDE SAMBA
- 佛爷芸: 机器学习算法原理总结系列---算法基础之(1)机器学习介绍
- 2.尾部的零
- LeetCode #743 Network Delay Time
- 集合总结,NIO总结