当前位置:网站首页>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
边栏推荐
- Mysql database (II) DML data operation statements and basic DQL statements
- Scoring system based on 485 bus
- ucore lab 2
- Dlib detects blink times based on video stream
- Global and Chinese market of RF shielding room 2022-2028: Research Report on technology, participants, trends, market size and share
- Word macro operation: convert the automatic number in the document into editable text type
- Interface test interview questions and reference answers, easy to grasp the interviewer
- Nest and merge new videos, and preset new video titles
- Differences between select, poll and epoll in i/o multiplexing
- Daily code 300 lines learning notes day 9
猜你喜欢

Eigen User Guide (Introduction)

Opencv recognition of face in image

Sorting odd and even subscripts respectively for leetcode simple problem

Stc-b learning board buzzer plays music

STC-B学习板蜂鸣器播放音乐

MySQL数据库(一)

ucore lab7 同步互斥 实验报告

How to write the bug report of software test?

Video scrolling subtitle addition, easy to make with this technique

几款开源自动化测试框架优缺点对比你知道吗?
随机推荐
ucore lab 2
Mysql database (III) advanced data query statement
Word macro operation: convert the automatic number in the document into editable text type
全网最详细的postman接口测试教程,一篇文章满足你
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
Rearrange spaces between words in leetcode simple questions
Thinking about three cups of tea
Video scrolling subtitle addition, easy to make with this technique
Eigen User Guide (Introduction)
Scoring system based on 485 bus
C4D quick start tutorial - creating models
Mysql database (II) DML data operation statements and basic DQL statements
软件测试Bug报告怎么写?
Public key box
Leetcode notes - dynamic planning -day6
Stc-b learning board buzzer plays music
MySQL transactions
ucore lab1 系统软件启动过程 实验报告
Interview answering skills for software testing
Global and Chinese markets of cobalt 2022-2028: Research Report on technology, participants, trends, market size and share