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

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

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

import java.util.*;
public class Main{
    public static void main(String []args){
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        ArrayList<Integer> set = new ArrayList();
        int head = in.nextInt();
        set.add(head);
        for(int i = 0;i<num-1;i++){
            int value = in.nextInt();
            int headInsert = in.nextInt();
            int insertIndex = set.indexOf(headInsert);
            set.add(insertIndex+1,value);
            
        }
        int deleteValue = in.nextInt();
        
        set.remove(set.indexOf(deleteValue));
        for(int i :set){
            System.out.print(i+" ");
        }
    }
}
全部评论

相关推荐

zYvv:双一流加大加粗再标红,然后广投。主要是获奖荣誉不够,建议开始不用追求大厂,去别的厂子刷下实习。
点赞 评论 收藏
分享
06-23 10:26
佳木斯大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务