From 4856f9786b82c9ca54f2759679e1ef7c9e7a34b0 Mon Sep 17 00:00:00 2001 From: PeixiZ <96801981+PeixiZ@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:49:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0C#=E7=A8=8B=E5=BA=8F=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=B8=89=E6=8C=87=E9=92=88=E6=84=9F=E8=A7=89?= =?UTF-8?q?=E4=BC=9A=E6=9B=B4=E5=BD=A2=E8=B1=A1=E8=A1=A8=E8=BF=B0=E9=93=BE?= =?UTF-8?q?=E8=A1=A8=E7=BF=BB=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0206.翻转链表.md | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md index 44146bb4..7db80fe1 100644 --- a/problems/0206.翻转链表.md +++ b/problems/0206.翻转链表.md @@ -628,6 +628,43 @@ impl Solution { } } ``` +C#: +三指针法, 感觉会更直观: + +```cs +public LinkNumbers Reverse() +{ + ///用三指针,写的过程中能够弥补二指针在翻转过程中的想象 + LinkNumbers pre = null; + var move = root; + var next = root; + + while (next != null) + { + next = next.linknext; + move.linknext = pre; + pre = move; + move = next; + } + root = pre; + return root; +} + +///LinkNumbers的定义 +public class LinkNumbers +{ + /// + /// 链表值 + /// + public int value { get; set; } + + /// + /// 链表指针 + /// + public LinkNumbers linknext { get; set; } +} +``` +