标签:style blog color io ar java for sp div
package jeetcode; import java.util.HashMap; public class jeetCode { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub /** * Definition for singly-linked list. public class ListNode { int val; * ListNode next; ListNode(int x) { val = x; next = null; } } */ class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; } } ListNode l1 = new ListNode(1); ListNode l2 = new ListNode(9); l2.next = new ListNode(9); ListNode l3 = new ListNode(0); ListNode p = l3; int jinwei = 0; while (l1 != null || l2 != null || jinwei != 0) { int plus = ((l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + jinwei); p.val = plus % 10; jinwei = plus / 10; ListNode now = new ListNode(0); l1 = l1 == null ? null : l1.next; l2 = l2 == null ? null : l2.next; if (l1 != null || l2 != null || jinwei != 0) { p.next = now; p = now; } else { p.next = null; } } while (l3 != null) { System.out.println(l3.val); l3 = l3.next; } } }
标签:style blog color io ar java for sp div
原文地址:http://www.cnblogs.com/bluedreamviwer/p/jeetcode.html