[LintCode] Delete Node in the Middle of Singly Linked List
文章目录
Problem
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
Note
就是把node.next.val赋给node,然后删掉node.next,用node直接连接node.next.next。
Solution
public class Solution {
public void deleteNode(ListNode node) {
if (node == null) return;
if (node.next != null) {
node.val = node.next.val;
node.next = node.next.next;
}
return;
}
}

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论