【LeetCode】24. Swap Nodes in Pairs C语言
来源:互联网 发布:github ssh项目源码 编辑:程序博客网 时间:2024/06/03 17:53
LeetCode解题心得,欢迎交流! 第二日
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; *///方法1struct ListNode* swapPairs(struct ListNode* head) { struct ListNode *dummy=(struct ListNode*)malloc(sizeof(struct ListNode)); dummy->next = head; struct ListNode *cur=dummy; while(cur->next!=NULL && cur->next->next!=NULL) { struct ListNode *first=cur->next; struct ListNode *second=cur->next->next; first->next = second->next; cur->next=second; second->next=first; cur=cur->next->next; } return dummy->next;} //方法2 递归struct ListNode* swapPairs(struct ListNode* head) { if(head == NULL || head->next ==NULL) return head; struct ListNode *p=head->next; head->next=swapPairs(head->next->next); p->next=head; return p;}
0 0
- Leetcode c语言-Swap Nodes in Pairs
- 【LeetCode】24. Swap Nodes in Pairs C语言
- 【C++】【LeetCode】24. Swap Nodes in Pairs
- [C语言][LeetCode][24]Swap Nodes in Pairs
- leetcode: Swap Nodes in Pairs (C++)
- 【LeetCode-24】Swap Nodes in Pairs(C++)
- Swap Nodes in Pairs(C语言)
- [LeetCode]24.Swap Nodes in Pairs
- 24. Swap Nodes in Pairs Leetcode Python
- LeetCode --- 24. Swap Nodes in Pairs
- LeetCode 24.Swap Nodes in Pairs
- [Leetcode] 24. Swap Nodes in Pairs
- 【LeetCode】24.Swap Nodes in Pairs
- [leetcode] 24.Swap Nodes in Pairs
- **LeetCode 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs LeetCode
- leetcode 24. Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs
- Java按行读写txt数据
- 正则学习
- Sapera LT 的配置
- 图书购买系统之实体类
- [More Effective C++]尽量使用C++风格的类型转换
- 【LeetCode】24. Swap Nodes in Pairs C语言
- 堆的介绍与应用
- golang报错: all goroutines are asleep
- 【Java之网络编程】3.UDP
- [BFS]199. Binary Tree Right Side View
- rt带宽限制浅析
- 多线程学习笔记
- 关于安卓动态加载的一点学习曲折
- 禁止iOS自动识别手机号