From badb2abbf5d1a2c4aa00fd447f88f84c18b551a6 Mon Sep 17 00:00:00 2001 From: huangge1199 Date: Mon, 7 Jun 2021 10:43:04 +0800 Subject: [PATCH] =?UTF-8?q?237:=E5=88=A0=E9=99=A4=E9=93=BE=E8=A1=A8?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor/cn/DeleteNodeInALinkedList.java | 66 +++++++++++++++++++ .../editor/cn/DeleteNodeInALinkedList.md | 35 ++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/main/java/leetcode/editor/cn/DeleteNodeInALinkedList.java create mode 100644 src/main/java/leetcode/editor/cn/DeleteNodeInALinkedList.md diff --git a/src/main/java/leetcode/editor/cn/DeleteNodeInALinkedList.java b/src/main/java/leetcode/editor/cn/DeleteNodeInALinkedList.java new file mode 100644 index 0000000..009e516 --- /dev/null +++ b/src/main/java/leetcode/editor/cn/DeleteNodeInALinkedList.java @@ -0,0 +1,66 @@ +//请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点。传入函数的唯一参数为 要被删除的节点 。 +// +// +// +// 现有一个链表 -- head = [4,5,1,9],它可以表示为: +// +// +// +// +// +// 示例 1: +// +// 输入:head = [4,5,1,9], node = 5 +//输出:[4,1,9] +//解释:给定你链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9. +// +// +// 示例 2: +// +// 输入:head = [4,5,1,9], node = 1 +//输出:[4,5,9] +//解释:给定你链表中值为 1 的第三个节点,那么在调用了你的函数之后,该链表应变为 4 -> 5 -> 9. +// +// +// +// +// 提示: +// +// +// 链表至少包含两个节点。 +// 链表中所有节点的值都是唯一的。 +// 给定的节点为非末尾节点并且一定是链表中的一个有效节点。 +// 不要从你的函数中返回任何结果。 +// +// Related Topics 链表 +// 👍 910 👎 0 + +package leetcode.editor.cn; + +import com.code.leet.entiy.ListNode; + +//237:删除链表中的节点 +public class DeleteNodeInALinkedList{ + public static void main(String[] args) { + //测试代码 + Solution solution = new DeleteNodeInALinkedList().new Solution(); + } + //力扣代码 + //leetcode submit region begin(Prohibit modification and deletion) +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode(int x) { val = x; } + * } + */ +class Solution { + public void deleteNode(ListNode node) { + node.val = node.next.val; + node.next = node.next.next; + } +} +//leetcode submit region end(Prohibit modification and deletion) + +} \ No newline at end of file diff --git a/src/main/java/leetcode/editor/cn/DeleteNodeInALinkedList.md b/src/main/java/leetcode/editor/cn/DeleteNodeInALinkedList.md new file mode 100644 index 0000000..20ed56a --- /dev/null +++ b/src/main/java/leetcode/editor/cn/DeleteNodeInALinkedList.md @@ -0,0 +1,35 @@ +

请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点。传入函数的唯一参数为 要被删除的节点

+ +

 

+ +

现有一个链表 -- head = [4,5,1,9],它可以表示为:

+ +

+ +

 

+ +

示例 1:

+ +
输入:head = [4,5,1,9], node = 5
+输出:[4,1,9]
+解释:给定你链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9.
+
+ +

示例 2:

+ +
输入:head = [4,5,1,9], node = 1
+输出:[4,5,9]
+解释:给定你链表中值为 1 的第三个节点,那么在调用了你的函数之后,该链表应变为 4 -> 5 -> 9.
+
+ +

 

+ +

提示:

+ + +
Related Topics
  • 链表
  • \n
  • 👍 910
  • 👎 0
  • \ No newline at end of file