fork download
  1. /**
  2.  * Definition for singly-linked list.
  3.  * public class ListNode {
  4.  * int val;
  5.  * ListNode next;
  6.  * ListNode(int x) { val = x; }
  7.  * }
  8.  */
  9. class Solution {
  10. public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
  11. int carry = 0;
  12. ListNode root = new ListNode(0);
  13. ListNode tempNode = root;
  14. int temp = 0;
  15. while(l1!=null && l2!=null){
  16. temp = l1.val + l2.val + carry;
  17. tempNode.next = new ListNode(temp%10);
  18. carry = temp/10;
  19. tempNode = tempNode.next;
  20. l1 = l1.next;
  21. l2 = l2.next;
  22. }
  23.  
  24. while(l1!=null){
  25. temp = l1.val + carry;
  26. tempNode.next = new ListNode(temp%10);
  27. carry = temp/10;
  28. tempNode = tempNode.next;
  29. l1 = l1.next;
  30. }
  31.  
  32. while(l2!=null){
  33. temp = l2.val + carry;
  34. tempNode.next = new ListNode(temp%10);
  35. carry = temp/10;
  36. tempNode = tempNode.next;
  37. l2 = l2.next;
  38. }
  39.  
  40. while(carry!=0){
  41. tempNode.next = new ListNode(carry);
  42. carry/=10;
  43. tempNode = tempNode.next;
  44. }
  45.  
  46. return root.next;
  47. }
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:10: error: cannot find symbol
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
                                  ^
  symbol:   class ListNode
  location: class Solution
Main.java:10: error: cannot find symbol
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
                                               ^
  symbol:   class ListNode
  location: class Solution
Main.java:10: error: cannot find symbol
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
           ^
  symbol:   class ListNode
  location: class Solution
Main.java:12: error: cannot find symbol
        ListNode root = new ListNode(0);
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:12: error: cannot find symbol
        ListNode root = new ListNode(0);
                            ^
  symbol:   class ListNode
  location: class Solution
Main.java:13: error: cannot find symbol
        ListNode tempNode = root;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:17: error: cannot find symbol
            tempNode.next = new ListNode(temp%10);
                                ^
  symbol:   class ListNode
  location: class Solution
Main.java:26: error: cannot find symbol
            tempNode.next = new ListNode(temp%10);
                                ^
  symbol:   class ListNode
  location: class Solution
Main.java:34: error: cannot find symbol
            tempNode.next = new ListNode(temp%10);
                                ^
  symbol:   class ListNode
  location: class Solution
Main.java:41: error: cannot find symbol
            tempNode.next = new ListNode(carry);
                                ^
  symbol:   class ListNode
  location: class Solution
10 errors
stdout
Standard output is empty