328. Odd Even Linked List
就是兩個指標,odd 和even的指標過程
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def oddEvenList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if not head or not head.next or not head.next.next:
return head
odd = head
even = head.next
dummy = head.next
while odd.next and even.next:
odd.next = even.next
odd = odd.next
even.next = odd.next
even = even.next
if even:
even.next = None
odd.next = dummy
return head
相關文章
- [LeetCode] 328. Odd Even Linked ListLeetCode
- LeetCode之Odd Even Linked List(Kotlin)LeetCodeKotlin
- LeetCode | 141 linked list cycleLeetCode
- Leetcode 206. Reverse Linked ListLeetCode
- 92. Reverse Linked List II
- [leetcode]linked-list-cycle-iiLeetCode
- LeetCode 382 Linked List Random NodeLeetCoderandom
- Leetcode 234. Palindrome Linked ListLeetCode
- Leetcode 142. Linked List Cycle IILeetCode
- LeetCode - Easy - 206. Reverse Linked ListLeetCode
- Leetcode 203. Remove Linked List ElementsLeetCodeREM
- Leetcode 237. Delete Node in a Linked ListLeetCodedelete
- LeetCode | 203. Remove Linked List ElementsLeetCodeREM
- 114-Flatten Binary Tree to Linked List
- [LeetCode] 2487. Remove Nodes From Linked ListLeetCodeREM
- [LeetCode] 430. Flatten a Multilevel Doubly Linked ListLeetCode
- LeetCode707:設計連結串列 Design Linked ListLeetCode
- 02-線性結構3 Reversing Linked List (25分)
- 【資料結構與演算法】——連結串列(Linked List)資料結構演算法
- 資料結構與演算法 | Leetcode 206:Reverse Linked List資料結構演算法LeetCode
- 資料結構與演算法 | Leetcode 141:Linked List Cycle資料結構演算法LeetCode
- 想了很久,一道Microsoft的筆試題目 —— Reversing Linked ListROS筆試
- LeetCode 83.Remove Duplicates from Sorted List(從已排序連結串列中除去重複) Easy/Linked ListLeetCodeREM排序
- 演算法與資料結構基礎 - 連結串列(Linked List)演算法資料結構
- 資料結構與演算法 | Leetcode 876. middle-of-the-linked-list資料結構演算法LeetCode
- 配置yilia/even
- [LeetCode] 1367. Linked List in Binary Tree 二叉樹中的連結串列LeetCode二叉樹
- [LeetCode Python 3] 876. Middle of the Linked List(連結串列的中間結點)LeetCodePython
- 【小白學演算法】5.連結串列(linked list)、連結串列的新增演算法
- LeetCode 之 JavaScript 解答第141題 —— 環形連結串列 I(Linked List Cycle I)LeetCodeJavaScript
- The really odd thing is that this presumed #1 QB
- C組group2 A - Odd Selection
- [ARC146C] Even XOR
- It's not even the whole quest. In this article
- 【kickstart 2018 round A】 Even Digits PythonGitPython
- Solution - Atcoder YPC2019E Odd Subrectangles
- 演算法與資料結構-連結串列((linked-list)-Java實現單向連結串列演算法資料結構Java
- CF2031F Penchick and Even Medians