首页 > 其他 > 详细

leetcode-面试题18-删除链表的节点

时间:2020-04-11 23:27:28      阅读:81      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

javaO(N)

 

技术分享图片
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode firstNode = new ListNode(-1);
        firstNode.next = head;
        ListNode curr = firstNode;
        while(curr!=null && curr.next != null){
            if(curr.next.val == val){
                curr.next = curr.next.next;
            }
            curr = curr.next;
        }
        return firstNode.next;
    }
}
java

 

leetcode-面试题18-删除链表的节点

原文:https://www.cnblogs.com/oldby/p/12683014.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!