1. // head = removeValue(head, 2);
    2. public static Node removeValue(Node head, int num) {
    3. // head来到第一个不需要删的位置
    4. while (head != null) {
    5. if (head.value != num) {
    6. break;
    7. }
    8. head = head.next;
    9. }
    10. //head来到第一个不需要删的位置
    11. Node pre = head;
    12. Node cur = head;
    13. while (cur != null) {
    14. if (cur.value == num) {
    15. pre.next = cur.next;
    16. } else {
    17. pre = cur;
    18. }
    19. cur = cur.next;
    20. }
    21. return head;
    22. }