当前位置:网站首页>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
边栏推荐
- How to become a good software tester? A secret that most people don't know
- 软件测试面试回答技巧
- 如何成为一个好的软件测试员?绝大多数人都不知道的秘密
- Leetcode notes - dynamic planning -day6
- Opencv recognition of face in image
- [HCIA continuous update] working principle of static route and default route
- Portapack application development tutorial (XVII) nRF24L01 launch B
- Leetcode simple question: check whether the numbers in the sentence are increasing
- ArrayList集合
- Interface test interview questions and reference answers, easy to grasp the interviewer
猜你喜欢

Introduction to safety testing

C4D quick start tutorial - creating models
![[pytorch] simple use of interpolate](/img/16/87aa8a49e60801404822fe644e70c8.jpg)
[pytorch] simple use of interpolate

ucore lab2 物理内存管理 实验报告

Mysql database (IV) transactions and functions

How to rename multiple folders and add unified new content to folder names

CSAPP Shell Lab 实验报告

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

Threads and thread pools

STC-B学习板蜂鸣器播放音乐
随机推荐
ArrayList集合
Global and Chinese markets of Iam security services 2022-2028: Research Report on technology, participants, trends, market size and share
Which version of MySQL does php7 work best with?
Mysql database (I)
Knowledge that you need to know when changing to software testing
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
Preface to the foundations of Hilbert geometry
[pytorch] simple use of interpolate
软件测试工作太忙没时间学习怎么办?
Want to change jobs? Do you know the seven skills you need to master in the interview software test
Mysql的事务
CSAPP shell lab experiment report
Leetcode notes - dynamic planning -day6
The maximum number of words in the sentence of leetcode simple question
Introduction to safety testing
Collection集合与Map集合
Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)
ucore lab 2
MySQL数据库(一)
Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share