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

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

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+" ");
        }
    }
}
全部评论

相关推荐

我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 15:36
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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