mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-26 13:06:07 +00:00
build
This commit is contained in:
@@ -427,8 +427,7 @@ comments: true
|
||||
|
||||
```csharp title="linked_list.cs"
|
||||
/* 在链表的节点 n0 之后插入节点 P */
|
||||
void insert(ListNode n0, ListNode P)
|
||||
{
|
||||
void insert(ListNode n0, ListNode P) {
|
||||
ListNode? n1 = n0.next;
|
||||
P.next = n1;
|
||||
n0.next = P;
|
||||
@@ -570,8 +569,7 @@ comments: true
|
||||
|
||||
```csharp title="linked_list.cs"
|
||||
/* 删除链表的节点 n0 之后的首个节点 */
|
||||
void remove(ListNode n0)
|
||||
{
|
||||
void remove(ListNode n0) {
|
||||
if (n0.next == null)
|
||||
return;
|
||||
// n0 -> P -> n1
|
||||
@@ -716,10 +714,8 @@ comments: true
|
||||
|
||||
```csharp title="linked_list.cs"
|
||||
/* 访问链表中索引为 index 的节点 */
|
||||
ListNode? access(ListNode head, int index)
|
||||
{
|
||||
for (int i = 0; i < index; i++)
|
||||
{
|
||||
ListNode? access(ListNode head, int index) {
|
||||
for (int i = 0; i < index; i++) {
|
||||
if (head == null)
|
||||
return null;
|
||||
head = head.next;
|
||||
@@ -882,11 +878,9 @@ comments: true
|
||||
|
||||
```csharp title="linked_list.cs"
|
||||
/* 在链表中查找值为 target 的首个节点 */
|
||||
int find(ListNode head, int target)
|
||||
{
|
||||
int find(ListNode head, int target) {
|
||||
int index = 0;
|
||||
while (head != null)
|
||||
{
|
||||
while (head != null) {
|
||||
if (head.val == target)
|
||||
return index;
|
||||
head = head.next;
|
||||
|
||||
Reference in New Issue
Block a user