Leetcode 66:plus One

Source: Internet
Author: User

Given a non-negative number represented as an array of digits, plus one to the number.

The digits is stored such, the most significant digit was at the head of the list.

Test instructions: An integer is stored in a bitwise array of int, arranged in the order of the highest bit in digits[0], the lowest bit in digits[n-1],//for example: 98, stored as: digits[0]=9; digits[1]=8;//: Add 1 from the last digit of the array, consider rounding, and if there is still a carry present after the digits[0] bit, add the rounding to the class solution {public:    Vector<int > PlusOne (vector<int> &digits) {        //important:please Reset any member data you declared, as        //The S Ame Solution instance'll be reused to each test case.        int a = 1;        Vector<int> ans;        Vector<int>::iterator it;        for (int i = digits.size ()-1;i >= 0;i--)        {            it = Ans.begin ();            int tmp = (A + digits[i])%;            A = (A + digits[i])/ten;            Ans.insert (it, TMP);        }        if (A! = 0)        {            it = Ans.begin ();            Ans.insert (it, a);        }                return ans;    };


Leetcode 66:plus One

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.