Skip to content

Commit 65338e5

Browse files
authored
feat: add swift implementation to lcci problem: No.02.03 (doocs#2616)
Signed-off-by: Lanre Adedara
1 parent f0aa04d commit 65338e5

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

lcci/02.03.Delete Middle Node/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ var deleteNode = function (node) {
114114
};
115115
```
116116

117+
```swift
118+
/**
119+
* public class ListNode {
120+
* var val: Int
121+
* var next: ListNode?
122+
* init(_ x: Int) {
123+
* self.val = x
124+
* self.next = nil
125+
* }
126+
* }
127+
*/
128+
class Solution {
129+
func deleteNode(_ node: ListNode?) {
130+
guard let node = node, let next = node.next else { return }
131+
node.val = next.val
132+
node.next = next.next
133+
}
134+
}
135+
```
136+
117137
<!-- tabs:end -->
118138

119139
<!-- end -->

lcci/02.03.Delete Middle Node/README_EN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ var deleteNode = function (node) {
109109
};
110110
```
111111

112+
```swift
113+
/**
114+
* public class ListNode {
115+
* var val: Int
116+
* var next: ListNode?
117+
* init(_ x: Int) {
118+
* self.val = x
119+
* self.next = nil
120+
* }
121+
* }
122+
*/
123+
class Solution {
124+
func deleteNode(_ node: ListNode?) {
125+
guard let node = node, let next = node.next else { return }
126+
node.val = next.val
127+
node.next = next.next
128+
}
129+
}
130+
```
131+
112132
<!-- tabs:end -->
113133

114134
<!-- end -->
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* public class ListNode {
3+
* var val: Int
4+
* var next: ListNode?
5+
* init(_ x: Int) {
6+
* self.val = x
7+
* self.next = nil
8+
* }
9+
* }
10+
*/
11+
class Solution {
12+
func deleteNode(_ node: ListNode?) {
13+
guard let node = node, let next = node.next else { return }
14+
node.val = next.val
15+
node.next = next.next
16+
}
17+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy