【LeetCode】Swap Nodes in Pairs 链表指针的应用
来源:互联网 发布:沈阳seo那家好 编辑:程序博客网 时间:2024/06/07 23:22
题目:swap nodes in pairs
<span style="font-size:18px;">/** * LeetCode Swap Nodes in Pairs * 题目:输入一个链表,要求将链表每相邻的两个节点交换位置后输出 * 思路:遍历一遍即可,时间复杂度O(n) * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */package javaTrain; public class Train12 {public ListNode swapPairs(ListNode head) {if(head == null || head.next == null) return null; ListNode pNode; pNode = head; while(pNode != null && pNode.next != null){ int temp; temp = pNode.val; pNode.val = pNode.next.val; pNode.next.val = temp; pNode = pNode.next.next; } return head; }}</span>
1 0
- 【LeetCode】Swap Nodes in Pairs 链表指针的应用
- Leetcode 线性表 Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs 单向链表操作
- LeetCode:Swap Nodes in Pairs
- LeetCode: Swap Nodes in Pairs
- [Leetcode] Swap Nodes in Pairs
- LeetCode : Swap Nodes in Pairs
- [LeetCode] Swap Nodes in Pairs
- Leetcode: Swap nodes in pairs
- [LeetCode]Swap Nodes in Pairs
- [LeetCode]Swap Nodes in Pairs
- LeetCode-Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- LeetCode | Swap Nodes in Pairs
- 【leetcode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- 【LeetCode】Swap Nodes in Pairs
- 数据库的三范式及mysql的InnoDB 和MyISAM区别
- Java非对称加密算法--RSA加密算法 原文http://blog.csdn.net/qiuzhping/article/details/44344373
- JAVA 开发平台的技术和框架(二)前端控制器:Struts2 ,Spring MVC
- Oculus Rift DK2 驱动安装教程
- 服务器上部署GIT上线命令
- 【LeetCode】Swap Nodes in Pairs 链表指针的应用
- POJ2586 Y2K Accounting Bug 贪心
- JAVA实现RSA加密解密
- 敏捷开发之Scrum扫盲篇
- 手把手教你捕获数据包
- C++ 函数中如何接收数量不定的函数参数
- php 操作数组 (合并,拆分,追加,查找,删除等)
- Aws BMP 两个环境之间的迁移步骤
- Machine Learning文章索引