TreeviewCopyright © aleen42 all right reserved, powered by aleen42

03. 删除中间节点

https://leetcode-cn.com/problems/delete-middle-node-lcci/

Java

/*
 * @Author: Goog Tech
 * @Date: 2020-07-19 22:29:43
 * @Description: https://leetcode-cn.com/problems/delete-middle-node-lcci/
 * @FilePath: \leetcode-googtech\面试题02\#03. 删除中间节点\Solution.java
 */ 

/**
 * 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;
    }
}

Python

'''
@Author: Goog Tech
@Date: 2020-07-19 22:29:49
@Description: https://leetcode-cn.com/problems/delete-middle-node-lcci/
@FilePath: \leetcode-googtech\面试题02\#03. 删除中间节点\Solution.py
'''
# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def deleteNode(self, node):
        """
        :type node: ListNode
        :rtype: void Do not return anything, modify node in-place instead.
        """
        # 更新待删除节点的值及指针
        node.val = node.next.val
        node.next = node.next.next
Copyright © GoogTech 2021 all right reserved,powered by GitbookLast update time : 2021-09-15 01:55:05

results matching ""

    No results matching ""