时间复杂度:O(n),n为链表的长度,需要遍历整个链表。

空间复杂度:O(n),n为递归栈的深度,最坏情况下链表中所有节点都需要被删除,递归栈的深度为n。

class Solution public ListNode removeElementsListNode head int val ifhead==null return head; return fheadval; 定义方法 public static ListNode fListNode hea

原文地址: https://www.cveoy.top/t/topic/bRgF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录