public static ListNode createLink(ListNode head, int data) {
        ListNode pre, cur, target;

        pre = null;
        cur = target = head;

        while (cur != null) {
            pre = cur;
            cur = cur.next;
        }
        
        while (target != null && target.val != data) {
            target = target.next;
        }
        
        if (target == null) {
            ListNode node = new ListNode(data);
            if (pre == null) {
                head = node;
            } else {
                pre.next = node;
            }
        } else {
            pre.next = target;
        }
        
        return head;
    }