添加C#版

This commit is contained in:
eeee0717
2023-05-25 15:51:34 +08:00
parent 44477f831b
commit 3965f2590c
4 changed files with 93 additions and 0 deletions

View File

@@ -412,6 +412,28 @@ struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
```
C#
```csharp
public class Solution {
public ListNode RemoveNthFromEnd(ListNode head, int n) {
ListNode dummpHead = new ListNode(0);
dummpHead.next = head;
var fastNode = dummpHead;
var slowNode = dummpHead;
while(n-- != 0 && fastNode != null)
{
fastNode = fastNode.next;
}
while(fastNode.next != null)
{
fastNode = fastNode.next;
slowNode = slowNode.next;
}
slowNode.next = slowNode.next.next;
return dummpHead.next;
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>