[leetcode]Swap Nodes in Pairs
来源:互联网 发布:知微数据 陈庆 编辑:程序博客网 时间:2024/06/05 20:59
题目:
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4
, you should return the list as 2->1->4->3
.
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
链接:https://oj.leetcode.com/problems/swap-nodes-in-pairs/
描述:链表中按对交换节点
solution by python:
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: # @param a ListNode # @return a ListNode def swapPairs(self, head): if head==None or head.next==None: return head h = head.next head.next = h.next h.next = head head.next = self.swapPairs(head.next) return h
0 0
- 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
- Leetcode: Swap Nodes in Pairs
- Leetcode Swap Nodes in Pairs
- LeetCode Swap Nodes in Pairs
- 2015年十项最热的IT技能
- ios设备使用tcpdump抓包
- Synchronized关键字详解
- linux ffmpeg 添加 Intel media sdk 编码器(1)
- c++操作mysql的API函数详解
- [leetcode]Swap Nodes in Pairs
- 实现网页页面跳转的几种方法
- First Missing Positive
- Android Fragment组件学习
- C++著名类库
- 深圳视晶无线技术有限公司 狗血经历
- The type org.springframework.dao.support.DaoSupport cannot be resolved. It is indirectly referenced
- OJ--黑豆传说
- Matlab注释函数legend详解