1 Star 0 Fork 0

曾铖坚 / day24-code

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
Test3.java 736 Bytes
Copy Edit Raw Blame History
曾铖坚 authored 2024-04-23 22:52 . 力扣第21道算法题
package com.itheima;
public class Test3 {
public static void main(String[] args) {
}
public ListNode removeNthFromEnd(ListNode head, int n) {
//虚拟头结点
ListNode dummy=new ListNode(0,head);
//头指针
ListNode first=head;
//尾指针
ListNode second =dummy;
//让头指针指到他应该到的位置
for(int i =0;i<n;i++){
first=first.next;
}
//头指针带动尾指针
while(first!=null){
first=first.next;
second=second.next;
}
//删除要删除的节点
second.next=second.next.next;
//返回真正的头结点
return dummy.next;
}
}
1
https://gitee.com/zeng-chengjian/day24-code.git
git@gitee.com:zeng-chengjian/day24-code.git
zeng-chengjian
day24-code
day24-code
master

Search