Skip to content

Commit 5a8bb66

Browse files
committed
feat: Add solution for LeetCode problem 206
1 parent b968188 commit 5a8bb66

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// 206. Reverse Linked List.swift
3+
// https://leetcode.com/problems/reverse-linked-list/description/
4+
// Algorithm
5+
//
6+
// Created by 홍승현 on 2024/05/04.
7+
//
8+
9+
import Foundation
10+
11+
final class LeetCode206 {
12+
func reverseList(_ node: ListNode?, _ prev: ListNode? = nil) -> ListNode? {
13+
guard let node else { return prev }
14+
15+
let next = node.next
16+
node.next = prev
17+
18+
return reverseList(next, node)
19+
}
20+
}

0 commit comments

Comments
 (0)