Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3965f25

Browse files
committed
添加C#版
1 parent 44477f8 commit 3965f25

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

‎problems/0019.删除链表的倒数第N个节点.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,28 @@ struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
412412

413413
```
414414
415+
C#:
416+
```csharp
417+
public class Solution {
418+
public ListNode RemoveNthFromEnd(ListNode head, int n) {
419+
ListNode dummpHead = new ListNode(0);
420+
dummpHead.next = head;
421+
var fastNode = dummpHead;
422+
var slowNode = dummpHead;
423+
while(n-- != 0 && fastNode != null)
424+
{
425+
fastNode = fastNode.next;
426+
}
427+
while(fastNode.next != null)
428+
{
429+
fastNode = fastNode.next;
430+
slowNode = slowNode.next;
431+
}
432+
slowNode.next = slowNode.next.next;
433+
return dummpHead.next;
434+
}
435+
}
436+
```
415437
<p align="center">
416438
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
417439
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>

‎problems/0142.环形链表II.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,34 @@ object Solution {
437437
}
438438
```
439439

440+
C#:
441+
```CSharp
442+
public class Solution
443+
{
444+
public ListNode DetectCycle(ListNode head)
445+
{
446+
ListNode fast = head;
447+
ListNode slow = head;
448+
while (fast != null && fast.next != null)
449+
{
450+
slow = slow.next;
451+
fast = fast.next.next;
452+
if (fast == slow)
453+
{
454+
fast = head;
455+
while (fast != slow)
456+
{
457+
fast = fast.next;
458+
slow = slow.next;
459+
}
460+
return fast;
461+
}
462+
}
463+
return null;
464+
}
465+
}
466+
```
467+
440468
<p align="center">
441469
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
442470
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>

‎problems/0203.移除链表元素.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,41 @@ class Solution {
596596
}
597597
```
598598

599+
C#
600+
```CSharp
601+
/**
602+
* Definition for singly-linked list.
603+
* public class ListNode {
604+
* public int val;
605+
* public ListNode next;
606+
* public ListNode(int val=0, ListNode next=null) {
607+
* this.val = val;
608+
* this.next = next;
609+
* }
610+
* }
611+
*/
612+
public class Solution
613+
{
614+
public ListNode RemoveElements(ListNode head, int val)
615+
{
616+
ListNode dummyHead = new ListNode(0,head);
617+
ListNode temp = dummyHead;
618+
while(temp.next != null)
619+
{
620+
if(temp.next.val == val)
621+
{
622+
temp.next = temp.next.next;
623+
}
624+
else
625+
{
626+
temp = temp.next;
627+
}
628+
}
629+
return dummyHead.next;
630+
}
631+
}
632+
```
633+
599634
<p align="center">
600635
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
601636
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>

‎problems/0977.有序数组的平方.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,14 @@ public class Solution {
488488
return result;
489489
}
490490
}
491+
492+
C# LINQ:
493+
```csharp
494+
public class Solution {
495+
public int[] SortedSquares(int[] nums) {
496+
return nums.Select(x => x * x).OrderBy(x => x).ToArray();
497+
}
498+
}
491499
```
492500
<p align="center">
493501
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /