您的位置:首页 > Web前端 > Node.js

LeetCode Delete Node in a Linked List

2015-11-15 05:50 513 查看
原题链接在这里:https://leetcode.com/problems/delete-node-in-a-linked-list/

单链表不能往回走,把下一个点复制到当前点,然后去掉下一个点。

AC Java:

/**
* Definition for singly-linked list.
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
public class Solution {
public void deleteNode(ListNode node) {
node.val = node.next.val;
node.next = node.next.next;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: