206. Reverse Linked List--LeetCode Record
Reverse a singly linked list.
/**
* Definition for singly-linked list.
* public class ListNode {
* public var val: Int
* public var next: ListNode?
* public init(_ val: Int) {
* self.val = val
* self.next = nil
* }
* }
*/
class Solution {
func reverseList(head: ListNode?) -> ListNode? {
if head == nil || head!.next == nil {
return head
}
var pre = head
var head = head!.next
pre!.next = nil
while head != nil {
var temp = head
head = head!.next
temp!.next = pre
pre = temp
}
return pre
}
}
相關文章
- Leetcode 206. Reverse Linked ListLeetCode
- 237. Delete Node in a Linked List--LeetCode RecorddeleteLeetCode
- LeetCode - Easy - 206. Reverse Linked ListLeetCode
- 92. Reverse Linked List II
- Leetcode Reverse Linked List IILeetCode
- Leetcode-Reverse Linked List IILeetCode
- leetcode刷題--Reverse Linked ListLeetCode
- Reverse Linked List II leetcode javaLeetCodeJava
- 344. Reverse String--LeetCode RecordLeetCode
- 每天一道LeetCode--206. Reverse Linked ListLeetCode
- 資料結構與演算法 | Leetcode 206:Reverse Linked List資料結構演算法LeetCode
- REVERSE關鍵字之REVERSE函式函式
- JavaScript reverse()JavaScript
- Reverse Key IndexesIndex
- BUUCTF reverse 3
- react-recordReact
- javascript 陣列 reverse()JavaScript陣列
- oracle reverse函式Oracle函式
- Reverse Card (Hard Version)
- hackme 【攻防世界】Reverse
- Daily record-SeptemberAI
- Simple python reverse shellPython
- leetcode Reverse IntegerLeetCode
- Why would a reverse index be useful ?Index
- Reverse Key Indexes (219)Index
- Reverse學習筆記筆記
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- pl/sql record 詳解SQL
- delete duplication record in sql serverdeleteSQLServer
- Leetcode 7 Reverse IntegerLeetCode
- LeetCode-Reverse BitsLeetCode
- js String新增 reverse()方法JS
- js reverse()函式的作用JS函式
- 4. render, redirect, HttpResponse, reverseHTTP
- Reverse Integer leetcode javaLeetCodeJava
- Java 16 新特性:record類Java
- Erlang中的Record詳解
- 淺析 record 使用場景