LinkedList Delete first element
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given a linked list. Delete the first appearance of the given integer.
Definition of a single linked list:
// Java class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; } }
// C++ class ListNode { public: int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} };
// C struct ListNode { int val; struct ListNode *next; };
Implement a function DeleteFirstElement that deletes the first appearance of element. If element is not in a list, do nothing. Function DeleteFirstElement must return the pointer to the head of updated list.
// Java ListNode DeleteFirstElement(ListNode head, int element)
// C, C++ ListNode* DeleteFirstElement(ListNode* head, int element)
Example
Let's delete element = 2. Function DeleteFirstElement returns the pointer to the head of updated list:
Submissions 966
Acceptance rate 31%