解法1是这样写吗,老师
来源:1-1 算法面试不仅仅是正确的回答问题

慕的地4573324
2021-04-16
class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
int count = 0;
//超时了
while(head.next != null){
count++;
}
int m = count - n ;//正数第m 个 的前一个
//保存head
ListNode temp = head;
for(int i = 1; i< m ; i++){
temp = temp.next;
}
temp.next = temp.next.next;//删除temp后面的第一个节点
return head;
}
}
写回答
1回答
-
liuyubobobo
2021-04-16
抱歉,你问的是针对我课程中的哪个章节的学习?对于 Leetcode 上哪个问题的什么解法一?
012021-04-16
相似问题