面试题 02.03:删除中间节点
This commit is contained in:
parent
eb3cf99dde
commit
779e7f5487
48
src/main/java/leetcode/editor/cn/DeleteMiddleNodeLcci.java
Normal file
48
src/main/java/leetcode/editor/cn/DeleteMiddleNodeLcci.java
Normal file
@ -0,0 +1,48 @@
|
||||
//若链表中的某个节点,既不是链表头节点,也不是链表尾节点,则称其为该链表的「中间节点」。
|
||||
//
|
||||
// 假定已知链表的某一个中间节点,请实现一种算法,将该节点从链表中删除。
|
||||
//
|
||||
// 例如,传入节点 c(位于单向链表 a->b->c->d->e->f 中),将其删除后,剩余链表为 a->b->d->e->f
|
||||
//
|
||||
//
|
||||
//
|
||||
// 示例:
|
||||
//
|
||||
//
|
||||
//输入:节点 5 (位于单向链表 4->5->1->9 中)
|
||||
//输出:不返回任何数据,从链表中删除传入的节点 5,使链表变为 4->1->9
|
||||
//
|
||||
//
|
||||
//
|
||||
// Related Topics 链表
|
||||
// 👍 111 👎 0
|
||||
|
||||
package leetcode.editor.cn;
|
||||
|
||||
import com.code.leet.entiy.ListNode;
|
||||
|
||||
//面试题 02.03:删除中间节点
|
||||
public class DeleteMiddleNodeLcci{
|
||||
public static void main(String[] args) {
|
||||
//测试代码
|
||||
Solution solution = new DeleteMiddleNodeLcci().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)
|
||||
|
||||
}
|
17
src/main/java/leetcode/editor/cn/DeleteMiddleNodeLcci.md
Normal file
17
src/main/java/leetcode/editor/cn/DeleteMiddleNodeLcci.md
Normal file
@ -0,0 +1,17 @@
|
||||
<p>若链表中的某个节点,既不是链表头节点,也不是链表尾节点,则称其为该链表的「中间节点」。</p>
|
||||
|
||||
<p>假定已知链表的某一个中间节点,请实现一种算法,将该节点从链表中删除。</p>
|
||||
|
||||
<p>例如,传入节点 <code>c</code>(位于单向链表 <code>a->b->c->d->e->f</code> 中),将其删除后,剩余链表为 <code>a->b->d->e->f</code></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>节点 5 (位于单向链表 4->5->1->9 中)
|
||||
<strong>输出:</strong>不返回任何数据,从链表中删除传入的节点 5,使链表变为 4->1->9
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<div><div>Related Topics</div><div><li>链表</li></div></div>\n<div><li>👍 111</li><li>👎 0</li></div>
|
Loading…
Reference in New Issue
Block a user