当前位置:网站首页>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
边栏推荐
- Report on the double computer experiment of scoring system based on 485 bus
- Opencv recognition of face in image
- Want to change jobs? Do you know the seven skills you need to master in the interview software test
- 12306: mom, don't worry about me getting the ticket any more (1)
- 如何成为一个好的软件测试员?绝大多数人都不知道的秘密
- What to do when programmers don't modify bugs? I teach you
- Knowledge that you need to know when changing to software testing
- Servlet
- 软件测试Bug报告怎么写?
- Global and Chinese market of barrier thin film flexible electronics 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
MySQL development - advanced query - take a good look at how it suits you
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
12306: mom, don't worry about me getting the ticket any more (1)
C4D quick start tutorial - creating models
转行软件测试必需要知道的知识
Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
ucore lab8 文件系统 实验报告
软件测试工作太忙没时间学习怎么办?
Want to change jobs? Do you know the seven skills you need to master in the interview software test
随机推荐
ucore lab7
Public key box
Iterators and generators
自动化测试中敏捷测试怎么做?
UCORE lab8 file system experiment report
Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
如何成为一个好的软件测试员?绝大多数人都不知道的秘密
遇到程序员不修改bug时怎么办?我教你
FSM和i2c实验报告
UCORE lab5 user process management experiment report
Stc-b learning board buzzer plays music 2.0
How to change XML attribute - how to change XML attribute
Brief description of compiler optimization level
Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)
Pedestrian re identification (Reid) - data set description market-1501
MySQL数据库(一)
软件测试有哪些常用的SQL语句?
[200 opencv routines] 98 Statistical sorting filter
Global and Chinese market of barrier thin film flexible electronics 2022-2028: Research Report on technology, participants, trends, market size and share
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)