Leetcode - Task Scheduler
Leetcode - Remove Duplicates from Sorted List II

Leetcode - Plus One Linked List

violet posted @ Aug 11, 2020 02:19:48 AM in 算法 with tags Algorithm java LinkedList , 10818 阅读

https://leetcode.com/problems/plus-one-linked-list/

Given a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer.

You may assume the integer do not contain any leading zero, except the number 0 itself.

The digits are stored such that the most significant digit is at the head of the list.

Example :

Input: [1,2,3]
Output: [1,2,4]

 

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode plusOne(ListNode head) {
        head = reverse(head);
        int carry = 1;
        ListNode node = head;
        ListNode prev = null;
        while(node != null) {
            int sum = node.val + carry;
            carry = 0;
            if (sum > 9) {
                carry = 1;
                sum -= 10;
            }
            node.val = sum;
            prev = node;
            node =  node.next;
        }
        if (carry == 1) {
            prev.next = new ListNode();
            prev.next.val = 1;
        }
        return reverse(head);
    }
    public ListNode reverse(ListNode head) {
        ListNode prev = null;
        ListNode node = head;
        while (node != null) {
            ListNode next = node.next;
            node.next = prev;
            prev = node;
            node = next;
        }
        return prev;
    }
}
Escorts in Chennai 说:
Sep 17, 2021 03:47:00 PM

I truly prefer to peruse a particularly mind-blowing blog. Thank you so much! keep having a good time.

Chennai Escorts Service Mambakkam Escorts Escorts Service in Vellore Alwarpet Escorts Service T Nagar Escort Escorts in Besant Nagar

Bangalore Escorts@gm 说:
Nov 06, 2021 08:43:09 PM

I'm unfathomably enchanted with your article. I love the way wherein you structure this article. Appreciative to you for allowing this stunning post to us.
<a href="http://www.a1delhiescort.in/excited-to-have-fun-in-bangalore.html">Bangalore Call Girls</a>
<a href="http://www.sonalisharma.co.in/bangalore-escorts.html">Bangalore Escorts Service</a>
<a href="http://www.yaina.in/bangalore-call-girls.html">Bangalore Escort</a>
<a href="https://www.jaipur-escort-service.com/bangalore-call-girls.html">Escort in Bangalore</a>
<a href="http://www.alyceescorts.com/bangalore-escorts.html">Call Girl in Bangalore</a>
<a href="http://www.aliyamumbaiescort.in/bangalore-escorts.html">Bangalore Call Girl</a>
<a href="http://www.janhavi.in/bangalore-escorts.html">Bangalore Escort Service</a>
<a href="https://www.ritudas.in/bangalore-escorts.html">Independent Bangalore Escorts</a>
<a href="http://www.riya-panjaban.in/escorts-in-bangalore.html">Independent Escorts in Bangalore</a>
<a href="http://www.thedelhiescortsservice.com/bangalore.html">High Profile Call Girls in Bangalore</a>
<a href="http://www.archanaa.in/escorts-location/bangalore-escorts.html">Independent Call Girls in Bangalore</a>
<a href="http://www.escortsservicesjaipur.in/bangalore-escorts.html">High Profile Escorts in Bangalore</a>
<a href="http://www.jaipurescorts.co.in/bangalore-call-girls.html">Independent Call Girl in Bangalore</a>
<a href="http://www.callgirlsindelhi.net/escorts-in-bangalore.html">Bangalore Escorts</a>
<a href="http://www.escortdehradun.com/bangalore-call-girls.html">Escorts in Bangalore</a>
<a href="https://www.mumbaiescortspriya.com/bangalore-call-girls.html">Call Girls in Bangalore</a>

Paharganj Escorts 说:
Jan 04, 2022 01:27:32 PM

https://www.ncrcallgirls.com/saket-escorts.html
https://www.ncrcallgirls.com/nehru-place-escorts.html
https://www.ncrcallgirls.com/vasant-vihar-escorts.html
https://www.ncrcallgirls.com/
https://ncrcallgirldelhi.wordpress.com/blog/
https://sharmasanvi350.wixsite.com/ncrcallgirls
https://61c9ab8220851.site123.me/
https://ncrcallgirls0.yolasite.com/blog/
https://ncrcallgirlsblog.jimdofree.com/

HRMS SBI 说:
Aug 04, 2022 12:51:05 PM

SBI HRMS is a self service ESS portal for all the employees of State Bank of India all across the country, and this portal serves as a Human Resource Management System for present working and retired employees of SBI in order to exercise different information and benefits through ‘Multi-factor Authorization’. HRMS SBI the SBI HRMS stands for State Bank of Indian Human Resource Management System which is an all in one platform to get different employee services right away such as details of the salary, Profile Information, Vacation, Career History, Apply Leave, Download Salary slip, View Pay or Pension details, Check Holidays, Apply Tour and other financial beneficial information of SBI working employee and pensioner. the SBI HRMS stands for State Bank of Indian Human Resource Management System which is an all in one platform to get different employee services right away such as details of the salary, Profile Information, Vacation, Career History.

हिन्दी-सवाल-पत्रों.c 说:
May 01, 2023 03:27:22 PM

Hindi Model Question Papers Bihar School 10th Exam Board BSEB, Bihar Board 10th Class Model Papers 2023 Matric Exam Pattern, BSEB Patna Board Matric 10th Model Papers 2023 Sample Questions, Bihar Board 10th Model Papers 2023 Download, हिन्दी-सवाल-पत्रों.com BSEB Matric Bihar matric model paper 2023 bseb 10th sample paper 2023, bihar board 10th model paper 2023 pdf, bihar board 10th class model test paper 2023, bseb matric previous sample paper class 10th bihar board model question paper, bseb matric model question paper 2023.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter