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

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

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

import java.util.*;
public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int total = sc.nextInt();
            int head = sc.nextInt();
            List<Integer>link = new ArrayList<>();
            link.add(head);
            for(int i = 0; i < total-1;i++){
                int value = sc.nextInt();
                int target = sc.nextInt();
                link.add(link.indexOf(target)+1,value);
            }
            int delete = sc.nextInt();
            link.remove(link.indexOf(delete));
            for(int i : link){
                System.out.print(i+" ");
            }
        }
    }    
}
全部评论

相关推荐

xxxxOxo:该催就催,想要你的不会因为催就挂,催了就挂的是因为本来就要挂你
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务