@@ -0,0 +1,1702 @@
+/*%0A Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.%0A%0ASupposed the linked list is 1 -%3E 2 -%3E 3 -%3E 4 and you are given the third node with value 3, the linked list should become 1 -%3E 2 -%3E 4 after calling your function.%0A*/%0A%0A%0Aimport java.io.*;%0Aimport java.util.*;%0A%0Apublic class DeleteNodeinaLinkedList %7B%0A%09//Definition for singly-linked list.%0A%09public static class ListNode %7B%0A%09%09int val;%0A%09%09ListNode next;%0A%09%09ListNode(int x) %7B val = x; %7D%0A%09%7D%0A%0A%09public static void deleteNode(ListNode node) %7B%0A        if(node == null) return;%0A        if(node.next == null) %7B%0A            node = null;%0A        %7D%0A        ListNode cur = node;%0A        while(cur.next != null && cur.next.next != null)%7B%0A            cur.val = cur.next.val;%0A            cur = cur.next;%0A        %7D%0A        cur.val = cur.next.val;%0A        cur.next = null;%0A        return;%0A    %7D%0A%09%0A%09public static void main(String%5B%5D args) %7B %0A%09%09ListNode head = new ListNode(1);%0A%09%09ListNode node2 = new ListNode(2);%0A%09%09ListNode node3 = new ListNode(3);%0A%09%09ListNode node4 = new ListNode(4);%0A%09%09ListNode node5 = new ListNode(5);%0A%09%09ListNode node6 = new ListNode(6);%0A%09%09ListNode node7 = new ListNode(7);%0A%09%09head.next = node2;%0A%09%09node2.next = node3;%0A%09%09node3.next = node4;%0A%09%09node4.next = node5;%0A%09%09node5.next = node6;%0A%09%09node6.next = node7;%0A%09%09node7.next = null;%0A%09%09System.out.print( %22List: %22);%0A%09%09ListNode curr = head;%0A%09%09while(curr != null)%7B%0A%09%09%09System.out.print( curr.val + %22 %22);%0A%09%09%09curr = curr.next;%0A%09%09%7D%0A%09    System.out.println();%0A%09%09deleteNode(node4);%0A%09%09curr = head;%0A%09%09System.out.println(%22Delete node 4:%22);%0A%09%09while(curr != null)%7B%0A%09%09%09System.out.print( curr.val + %22 %22);%0A%09%09%09curr = curr.next;%0A%09%09%7D%0A%09    System.out.println();%0A%09%09return;%0A%09%7D%09%0A%7D%0A

delete node - change node value