A SIMPLE SOLUTION


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

    It's maybe a simple solution for this problem.


Log in to reply
 

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