# 0369. Plus One Linked List ###### tags: `Leetcode` `Medium` `Linked List` Link: https://leetcode.com/problems/plus-one-linked-list/ ## 思路 recursion找到下一位的carry 加到当前node上即可 ## Code ```java= class Solution { public ListNode plusOne(ListNode head) { ListNode dummyNode = new ListNode(0); dummyNode.next = head; compute(dummyNode); if(dummyNode.val==0) return head; else return dummyNode; } private int compute(ListNode curr){ int val; if(curr.next==null){ val = curr.val+1; } else{ int carry = compute(curr.next); val = curr.val+carry; } curr.val = val%10; return val/10; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up