当前位置:网站首页>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
边栏推荐
- Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share
- 软件测试需求分析之什么是“试纸测试”
- UCORE LaB6 scheduler experiment report
- ucore lab7 同步互斥 实验报告
- Face and eye recognition based on OpenCV's own model
- 全网最详细的postman接口测试教程,一篇文章满足你
- Lab 8 文件系统
- ucore lab 2
- ucore lab8 文件系统 实验报告
- In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
猜你喜欢
软件测试需求分析之什么是“试纸测试”
软件测试面试要问的性能测试术语你知道吗?
![[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)](/img/3a/aadde60352c42199ba287a6997acfa.jpg)
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)

MySQL development - advanced query - take a good look at how it suits you

What are the commonly used SQL statements in software testing?

Opencv recognition of face in image

51 lines of code, self-made TX to MySQL software!

Réponses aux devoirs du csapp 7 8 9

The maximum number of words in the sentence of leetcode simple question

How to build a nail robot that can automatically reply
随机推荐
[HCIA continuous update] advanced features of routing
HackTheBox-Emdee five for life
Face and eye recognition based on OpenCV's own model
ucore lab2 物理内存管理 实验报告
Mysql database (V) views, stored procedures and triggers
几款开源自动化测试框架优缺点对比你知道吗?
Differences between select, poll and epoll in i/o multiplexing
Word macro operation: convert the automatic number in the document into editable text type
[pytorch] simple use of interpolate
Winter vacation daily question - maximum number of balloons
线程及线程池
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
Preface to the foundations of Hilbert geometry
Contest3145 - the 37th game of 2021 freshman individual training match_ A: Prizes
Thinking about three cups of tea
转行软件测试必需要知道的知识
The wechat red envelope cover designed by the object is free! 16888
The latest query tracks the express logistics and analyzes the method of delivery timeliness
Introduction to variable parameters
MySQL数据库(二)DML数据操作语句和基本的DQL语句