2_solution.java - Definition for singly-linked list public class ListNode int val ListNode next ListNode(int x val = x class Solution public ListNode

2_solution.java - Definition for singly-linked list public...

This preview shows page 1 out of 1 page.

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode preNode = new ListNode(0); // 初始化头节点的前一个节点 ListNode current = preNode; int carry = 0; // 初始化进位 carry = 0 ListNode p = l1; // 初始化 p q l1 l2 的头部 ListNode q = l2; int x, y; int sum; while (p != null || q != null)
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

  • Spring '13
  • forget
  • 头节点

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes