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 public class Solution {
10     public ListNode plusOne(ListNode head) {
11         if (helper(head) == 0) {
12             return head;
13         } 
14         ListNode result = new ListNode(1);
15         result.next = head;
16         return result;
17     }
18     
19     private int helper(ListNode head) {
20         if (head == null) {
21             return 1;
22         }
23         
24         int current = helper(head.next);
25         int nextLevel = 0;
26         nextLevel = (head.val + current) / 10;
27         head.val = (head.val + current) % 10;
28         return nextLevel;
29     }
30 }

 

posted on 2016-06-29 13:50  keepshuatishuati  阅读(154)  评论(0编辑  收藏  举报