当前位置:网站首页>LeetCode#237. Delete nodes in the linked list
LeetCode#237. Delete nodes in the linked list
2022-07-06 15:21:00 【Rufeng ZHHH】
Please write a function , be used for Delete a specific node in the single linked list . When designing functions, you need to pay attention to , You can't access the head node of the linked list head , Direct access only The node to be deleted .
The topic data ensures that the nodes to be deleted Not the end node .
Example 1:

Input :head = [4,5,1,9], node = 5
Output :[4,1,9]
explain : Specifies that the value in the linked list is 5 Second node of , So after calling your function , The list should be 4 -> 1 -> 9
Example 2:

Input :head = [4,5,1,9], node = 1
Output :[4,5,9]
explain : Specifies that the value in the linked list is 1 The third node of , So after calling your function , The list should be 4 -> 5 -> 9
Example 3:
Input :head = [1,2,3,4], node = 3
Output :[1,2,4]
Example 4:
Input :head = [0,1], node = 0
Output :[1]
Example 5:
Input :head = [-3,5,-99], node = -3
Output :[5,-99]
Tips :
The number range of nodes in the linked list is [2, 1000]
-1000 <= Node.val <= 1000
The value of each node in the linked list is unique
Nodes to be deleted node yes A valid node in the linked list , And Not the end node
source : Power button (LeetCode)
link : Power button
This problem can be solved as long as we delete the specified node , Because the title has stated that this node is not the tail node , We can put node.val Locate the node.next.val, meanwhile node.next=node.next.next that will do .
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
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边栏推荐
- How to change XML attribute - how to change XML attribute
- The wechat red envelope cover designed by the object is free! 16888
- 软件测试行业的未来趋势及规划
- 软件测试工作太忙没时间学习怎么办?
- ucore Lab 1 系统软件启动过程
- China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
- [HCIA continuous update] working principle of static route and default route
- Portapack application development tutorial (XVII) nRF24L01 launch B
- 软件测试有哪些常用的SQL语句?
- How to become a good software tester? A secret that most people don't know
猜你喜欢

In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.

Description of Vos storage space, bandwidth occupation and PPS requirements

ucore lab5用户进程管理 实验报告

ucore lab6 调度器 实验报告

Crawler series of learning while tapping (3): URL de duplication strategy and Implementation

线程及线程池

Lab 8 file system

Leetcode simple question: check whether the numbers in the sentence are increasing

How to become a good software tester? A secret that most people don't know

Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)
随机推荐
CSAPP shell lab experiment report
Global and Chinese markets for GaN on diamond semiconductor substrates 2022-2028: Research Report on technology, participants, trends, market size and share
HackTheBox-Emdee five for life
Eigen User Guide (Introduction)
Mysql database (I)
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
Face and eye recognition based on OpenCV's own model
Stc-b learning board buzzer plays music
Sorting odd and even subscripts respectively for leetcode simple problem
Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)
ucore lab7
Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
UCORE lab7 synchronous mutual exclusion experiment report
Leetcode notes - dynamic planning -day7
What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
If the position is absolute, touchablehighlight cannot be clicked - touchablehighlight not clickable if position absolute
Global and Chinese market of portable and handheld TVs 2022-2028: Research Report on technology, participants, trends, market size and share
Do you know the performance testing terms to be asked in the software testing interview?
Global and Chinese market of DVD recorders 2022-2028: Research Report on technology, participants, trends, market size and share