当前位置:网站首页>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
边栏推荐
- Mysql的事务
- The most detailed postman interface test tutorial in the whole network. An article meets your needs
- Global and Chinese market of pinhole glossmeter 2022-2028: Research Report on technology, participants, trends, market size and share
- 如何成为一个好的软件测试员?绝大多数人都不知道的秘密
- 51 lines of code, self-made TX to MySQL software!
- Threads et pools de threads
- ArrayList set
- [pytorch] simple use of interpolate
- How to rename multiple folders and add unified new content to folder names
- 遇到程序员不修改bug时怎么办?我教你
猜你喜欢
The latest query tracks the express logistics and analyzes the method of delivery timeliness
What to do when programmers don't modify bugs? I teach you
CSAPP家庭作業答案7 8 9章
UCORE lab1 system software startup process experimental report
ucore lab7 同步互斥 实验报告
基于485总线的评分系统
Brief introduction to libevent
Your wechat nickname may be betraying you
ucore lab8 文件系统 实验报告
Heap, stack, queue
随机推荐
基于485总线的评分系统
Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share
Report on the double computer experiment of scoring system based on 485 bus
The latest query tracks the express logistics and analyzes the method of delivery timeliness
Investment should be calm
The minimum number of operations to convert strings in leetcode simple problem
软件测试Bug报告怎么写?
Example 071 simulates a vending machine, designs a program of the vending machine, runs the program, prompts the user, enters the options to be selected, and prompts the selected content after the use
Threads and thread pools
Servlet
pytest
Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
Do you know the advantages and disadvantages of several open source automated testing frameworks?
Maximum nesting depth of parentheses in leetcode simple questions
How to build a nail robot that can automatically reply
Global and Chinese market of RF shielding room 2022-2028: Research Report on technology, participants, trends, market size and share
Future trend and planning of software testing industry
Global and Chinese market of goat milk powder 2022-2028: Research Report on technology, participants, trends, market size and share
Stc-b learning board buzzer plays music
Global and Chinese markets for GaN on diamond semiconductor substrates 2022-2028: Research Report on technology, participants, trends, market size and share