题解 | #从单向链表中删除指定值的节点#

从单向链表中删除指定值的节点

https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f

using System;
using System.Collections.Generic;
using System.Linq;

public class Program {
    public static void Main() {
        var input = Console.ReadLine().Split(" ").Select(r => int.Parse(r)).ToList();
        var count = input[0] * 2;
        var li = new List<int> { input[1] };
        for (var i = 2; i < count; i += 2)
        {
            var index = li.IndexOf(input[i + 1]);
            li.Insert(index+1, input[i]);
        }

        li.Remove(input.Last());
        Console.WriteLine(string.Join(" ", li));
    }
}

全部评论

相关推荐

一天代码十万三:这都不能算简历吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务