当前位置:网站首页>LeetCode#19. Delete the penultimate node of the linked list
LeetCode#19. Delete the penultimate node of the linked list
2022-07-06 15:21:00 【Rufeng ZHHH】
For this problem, we can first get the sum of the number of nodes in the linked list ( Here I use count To express ), Then judge when the special situation ( Request to delete the first node ) And normal operation , Then carry out the corresponding steps .
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
count=0
pre=head
cur=head
while pre != None:
count+=1
pre=pre.next # Get the length count
if count-n==0:
return head.next
for i in range(count-n-1):
cur=cur.next
cur.next=cur.next.next
return head
边栏推荐
- The number of reversing twice in leetcode simple question
- 遇到程序员不修改bug时怎么办?我教你
- CSAPP Shell Lab 实验报告
- 软件测试有哪些常用的SQL语句?
- How to write the bug report of software test?
- Scoring system based on 485 bus
- MySQL数据库(二)DML数据操作语句和基本的DQL语句
- Differences between select, poll and epoll in i/o multiplexing
- What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
- Mysql的事务
猜你喜欢
How to become a good software tester? A secret that most people don't know
Interface test interview questions and reference answers, easy to grasp the interviewer
Daily code 300 lines learning notes day 9
ucore lab7 同步互斥 实验报告
Threads and thread pools
接口测试面试题及参考答案,轻松拿捏面试官
Mysql database (I)
Scoring system based on 485 bus
Jupyter installation and use tutorial
HackTheBox-Emdee five for life
随机推荐
Cadence physical library lef file syntax learning [continuous update]
Global and Chinese markets of PIM analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
Brief description of compiler optimization level
Preface to the foundations of Hilbert geometry
Global and Chinese market of pinhole glossmeter 2022-2028: Research Report on technology, participants, trends, market size and share
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
[HCIA continuous update] working principle of static route and default route
Stc-b learning board buzzer plays music 2.0
The minimum sum of the last four digits of the split digit of leetcode simple problem
基于485总线的评分系统双机实验报告
Heap, stack, queue
Collection集合与Map集合
Global and Chinese market of RF shielding room 2022-2028: Research Report on technology, participants, trends, market size and share
软件测试面试要问的性能测试术语你知道吗?
Investment should be calm
ArrayList set
ucore lab5
接口测试面试题及参考答案,轻松拿捏面试官
How to change XML attribute - how to change XML attribute
Do you know the advantages and disadvantages of several open source automated testing frameworks?