File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed
src/main/swift/g0001_0100/s0019_remove_nth_node_from_end_of_list Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -52,32 +52,32 @@ Here's the implementation:
5252
5353``` swift
5454class Solution {
55- func removeNthFromEnd (_ head : ListNode? , _ n : Int ) -> ListNode? {
56- guard ((head? .next ) != nil ), n > 0 else {return nil }
55+ func removeNthFromEnd (_ head : ListNode? , _ n : Int ) -> ListNode? {
56+ guard ((head? .next ) != nil ), n > 0 else {return nil }
5757 var count = 0
58- var current = head
58+ var current = head
5959 while let currentNode = current{
6060 count += 1
6161 current = currentNode.next
62- }
62+ }
6363 current = head
64- count = count - n + 1
65- var prev: ListNode?
66- while let currentNode = current {
67- count -= 1
68- if count == 0 {
64+ count = count - n + 1
65+ var prev: ListNode?
66+ while let currentNode = current {
67+ count -= 1
68+ if count == 0 {
6969 if prev == nil {
7070 current = current? .next
7171 return current
7272 } else {
7373 prev? .next = current? .next
7474 }
7575 break
76- }
76+ }
7777 prev = current
78- current = current? .next
79- }
80- return head
78+ current = current? .next
79+ }
80+ return head
8181 }
8282}
8383```
You can’t perform that action at this time.
0 commit comments