java tail recursive solution


  • 0
    C
    public class Solution {
        public ListNode removeElements(ListNode head, int val) {
            if (head == null) return head;
            ListNode tail = removeElements(head.next, val);
            if (head.val == val)
                return tail;
            else {
                head.next = tail;
                return head;
            }
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.