<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bigint Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/bigint/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/bigint/</link>
	<description></description>
	<lastBuildDate>Thu, 11 Apr 2019 05:06:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>bigint Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/bigint/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 66. Plus One</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-66-plus-one/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-66-plus-one/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Thu, 11 Apr 2019 05:05:36 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[bigint]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[math]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5027</guid>

					<description><![CDATA[<p>Given a&#160;non-empty&#160;array of digits&#160;representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-66-plus-one/">花花酱 LeetCode 66. Plus One</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given a&nbsp;<strong>non-empty</strong>&nbsp;array of digits&nbsp;representing a non-negative integer, plus one to the integer.</p>



<p>The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.</p>



<p>You may assume the integer does not contain any leading zero, except the number 0 itself.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted; crayon:false"><strong>Input:</strong> [1,2,3]
<strong>Output:</strong> [1,2,4]
<strong>Explanation:</strong> The array represents the integer 123.
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted; crayon:false"><strong>Input:</strong> [4,3,2,1]
<strong>Output:</strong> [4,3,2,2]
<strong>Explanation:</strong> The array represents the integer 4321.</pre>



<p><strong>Solution: Big Integer</strong></p>



<p>Process from right to left (lest significant to most signification). Use carry to indicate whether need +1 for next digit or not.</p>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">c++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  vector&lt;int&gt; plusOne(vector&lt;int&gt;&amp; digits) {
    int carry = 1;
    for (int i = digits.size() - 1; i &gt;= 0; --i) {
      digits[i] += carry;
      carry = digits[i] / 10;
      digits[i] %= 10;
    }
    if (carry) digits.insert(begin(digits), carry);
    return digits;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-66-plus-one/">花花酱 LeetCode 66. Plus One</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/math/leetcode-66-plus-one/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
