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

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

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

相关推荐

喜欢疯狂星期四的猫头鹰在研究求职打法:短作业优先
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务