typedef struct ListNode Node;

Node* find(Node* head, int val)
{
    Node* tmp = (Node*)malloc(sizeof(Node));
    if(!head)
        return NULL;
    tmp=head;
    
    if(head->val==val)
        return head;
    while(tmp->next->val!=val&&tmp->next!=NULL)
        tmp=tmp->next;
    if(tmp->next==NULL)
        return NULL;
    return tmp->next;
    
}
    
struct ListNode* deleteNode(struct ListNode* head, int val ) {
    
	Node* tmp = (Node*)malloc(sizeof(Node));
    Node* node = find(head, val);
	if (!head||!node)
		return head;
    
	if (node->next != NULL)
	{
		node->val = node->next->val;
		tmp = node->next;
		node->next = node->next->next;
		free(tmp);
		tmp = NULL;
	}
	else if ((head) == (node))
	{
		free(node);
		node = NULL;
		head = NULL;
	}
	else
	{
		tmp = head;
		while (tmp->next != node)
			tmp = tmp->next;
		tmp->next = NULL;
		free(node);
		node = NULL;
	}
    return head;
}