0
Q:

new listnode(0) meaning

ListNode dummy = new ListNode(0);
dummy.next = head;
0
ListNode fast = head;
ListNode slow = head;

while (fast != null && fast.next != null) {
    slow = slow.next;
    fast = fast.next.next;
}
-1
public class ListNode {
    int val;
    ListNode next;
    ListNode(int x) {
        val = x;
        next = null;
    }
}
0
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
    int sizeA = 0, sizeB = 0;
    ListNode ptrA = headA, ptrB = headB;

    while (ptrA != null) {
        ptrA = ptrA.next;
        sizeA++;
    }

    while (ptrB != null) {
        ptrB = ptrB.next;
        sizeB++;
    }

    int diff = sizeA - sizeB;
    if (diff > 0) {
        while (diff-- > 0) {
            headA = headA.next;
        }
    } else {
        while (diff++ < 0) {
            headB = headB.next;
        }
    }

    while (headA != headB) {
        headA = headA.next;
        headB = headB.next;
    }

    return headA;
}
0
node.val = node.next.val;
node.next = node.next.next;
0
int size = 0;
while (node != null) {
    node = node.next;
    size++;
}
0

New to Communities?

Join the community