<?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>base Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/base/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/base/</link>
	<description></description>
	<lastBuildDate>Sun, 28 Nov 2021 22:36:10 +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>base Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/base/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 168. Excel Sheet Column Title</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-168-excel-sheet-column-title/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-168-excel-sheet-column-title/#comments</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 28 Nov 2021 22:24:48 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[base]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[math]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8880</guid>

					<description><![CDATA[<p>Given an integer&#160;columnNumber, return&#160;its corresponding column title as it appears in an Excel sheet. For example: A -> 1 B -> 2 C -> 3&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-168-excel-sheet-column-title/">花花酱 LeetCode 168. Excel Sheet Column Title</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 an integer&nbsp;<code>columnNumber</code>, return&nbsp;<em>its corresponding column title as it appears in an Excel sheet</em>.</p>



<p>For example:</p>



<pre class="wp-block-preformatted;crayon:false">A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28 
...
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> columnNumber = 1
<strong>Output:</strong> "A"
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> columnNumber = 28
<strong>Output:</strong> "AB"
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> columnNumber = 701
<strong>Output:</strong> "ZY"
</pre>



<p><strong>Example 4:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> columnNumber = 2147483647
<strong>Output:</strong> "FXSHRXW"
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= columnNumber &lt;= 2<sup>31</sup>&nbsp;- 1</code></li></ul>



<h2><strong>Solution: Base conversion</strong></h2>



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



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

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  string convertToTitle(int n) {
    string ans;
    do {
      n--;
      ans += 'A' + (char)(n % 26);
      n /= 26;
    } while (n);
    reverse(begin(ans), end(ans));
    return ans;
  }
};</pre>
</div></div>



<h2><strong>Related Problems</strong></h2>



<ul><li><a href="https://zxi.mytechroad.com/blog/math/leetcode-171-excel-sheet-column-number/" data-type="post" data-id="8884">花花酱 LeetCode 171. Excel Sheet Column Number</a></li></ul>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-168-excel-sheet-column-title/">花花酱 LeetCode 168. Excel Sheet Column Title</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-168-excel-sheet-column-title/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 1837. Sum of Digits in Base K</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-1837-sum-of-digits-in-base-k/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-1837-sum-of-digits-in-base-k/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 25 Apr 2021 16:04:05 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[base]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[math]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8385</guid>

					<description><![CDATA[<p>Given an integer&#160;n&#160;(in base&#160;10) and a base&#160;k, return&#160;the&#160;sum&#160;of the digits of&#160;n&#160;after&#160;converting&#160;n&#160;from base&#160;10&#160;to base&#160;k. After converting, each digit should be interpreted as a base&#160;10&#160;number, and the&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-1837-sum-of-digits-in-base-k/">花花酱 LeetCode 1837. Sum of Digits in Base K</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 an integer&nbsp;<code>n</code>&nbsp;(in base&nbsp;<code>10</code>) and a base&nbsp;<code>k</code>, return&nbsp;<em>the&nbsp;<strong>sum</strong>&nbsp;of the digits of&nbsp;</em><code>n</code><em>&nbsp;<strong>after</strong>&nbsp;converting&nbsp;</em><code>n</code><em>&nbsp;from base&nbsp;</em><code>10</code><em>&nbsp;to base&nbsp;</em><code>k</code>.</p>



<p>After converting, each digit should be interpreted as a base&nbsp;<code>10</code>&nbsp;number, and the sum should be returned in base&nbsp;<code>10</code>.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 34, k = 6
<strong>Output:</strong> 9
<strong>Explanation: </strong>34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 10, k = 10
<strong>Output:</strong> 1
<strong>Explanation: </strong>n is already in base 10. 1 + 0 = 1.
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= n &lt;= 100</code></li><li><code>2 &lt;= k &lt;= 10</code></li></ul>



<h2><strong>Solution: Base Conversion</strong></h2>



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



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

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int sumBase(int n, int k) {
    int ans = 0;
    while (n) {
      ans += n % k;
      n /= k;
    }
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-1837-sum-of-digits-in-base-k/">花花酱 LeetCode 1837. Sum of Digits in Base K</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-1837-sum-of-digits-in-base-k/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 504. Base 7</title>
		<link>https://zxi.mytechroad.com/blog/simulation/leetcode-504-base-7/</link>
					<comments>https://zxi.mytechroad.com/blog/simulation/leetcode-504-base-7/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Fri, 17 Aug 2018 16:03:08 +0000</pubDate>
				<category><![CDATA[Simulation]]></category>
		<category><![CDATA[base]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=3571</guid>

					<description><![CDATA[<p>Problem Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202" Example 2: Input: -7 Output: "-10" Note: The input will&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-504-base-7/">花花酱 LeetCode 504. Base 7</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><iframe width="500" height="375" src="https://www.youtube.com/embed/fX6fh9B62vE?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<h1>Problem</h1>
<p>Given an integer, return its base 7 string representation.</p>
<p><b>Example 1:</b></p>
<pre class="crayon:false"><b>Input:</b> 100
<b>Output:</b> "202"
</pre>
<p><b>Example 2:</b></p>
<pre class="crayon:false"><b>Input:</b> -7
<b>Output:</b> "-10"
</pre>
<p><b>Note:</b> The input will be in range of [-1e7, 1e7].</p>
<h1><strong>Solution: Simulation</strong></h1>
<p>Time complexity: O(logn)</p>
<p>Space complexity: O(logn)</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time: 4 ms
class Solution {
public:
  string convertToBase7(int num) {
    bool is_nagetive = num&lt;0;
    num = abs(num);
    string ans;
    do {
        ans += ('0' + (num % 7));
        num /= 7;
    } while (num &gt; 0);
    
    if (is_nagetive)
        ans += "-";
    
    reverse(begin(ans), end(ans));
    
    return ans;
  }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-504-base-7/">花花酱 LeetCode 504. Base 7</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/simulation/leetcode-504-base-7/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
