mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-02 18:39:09 +08:00
添加C#版
This commit is contained in:
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user