<?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>division Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/division/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/division/</link>
	<description></description>
	<lastBuildDate>Thu, 22 Mar 2018 15:44:57 +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>division Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/division/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 553. Optimal Division</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-553-optimal-division/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-553-optimal-division/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Thu, 22 Mar 2018 15:44:46 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[division]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[medium]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=2291</guid>

					<description><![CDATA[<p>Problem https://leetcode.com/problems/optimal-division/description/ 题目大意：给你一个连除的表达式，让你加一些括号使得表达式的值最大。 Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -&#62; 2 / 3 / 4.&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-553-optimal-division/">花花酱 LeetCode 553. Optimal Division</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Problem</h1>
<p><a href="https://leetcode.com/problems/optimal-division/description/">https://leetcode.com/problems/optimal-division/description/</a></p>
<p>题目大意：给你一个连除的表达式，让你加一些括号使得表达式的值最大。</p>
<p>Given a list of <b>positive integers</b>, the adjacent integers will perform the float division. For example, [2,3,4] -&gt; 2 / 3 / 4.</p>
<p>However, you can add any number of parenthesis at any position to change the priority of operations. You should find out how to add parenthesis to get the <b>maximum</b> result, and return the corresponding expression in string format. <b>Your expression should NOT contain redundant parenthesis.</b></p>
<h2><b>Example:</b></h2>
<pre class="crayon:false"><b>Input:</b> [1000,100,10,2]
<b>Output:</b> "1000/(100/10/2)"
<b>Explanation:</b>
1000/(100/10/2) = 1000/((100/10)/2) = 200
However, the bold parenthesis in "1000/(<b>(</b>100/10<b>)</b>/2)" are redundant, 
since they don't influence the operation priority. So you should return "1000/(100/10/2)". 

Other cases:
1000/(100/10)/2 = 50
1000/(100/(10/2)) = 50
1000/100/10/2 = 0.5
1000/100/(10/2) = 2
</pre>
<h2><b>Note:</b></h2>
<ol>
<li>The length of the input array is [1, 10].</li>
<li>Elements in the given array will be in range [2, 1000].</li>
<li>There is only one optimal division for each test case.</li>
</ol>
<h1>Solution: Math</h1>
<p>For: X1/X2/X3/&#8230;/Xn, X1/(X2/X3/&#8230;/Xn) &gt; X1/X2/(X3/&#8230;/Xn) &gt; X1/X2/X3/(&#8230;/Xn)</p>
<p>X1/(X2/X3/&#8230;/Xn) is the max value.</p>
<p>Time complexity: O(n)</p>
<p>Space complexity: O(n)</p>
<p>C++</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time: 5 ms
class Solution {
public:
  string optimalDivision(vector&lt;int&gt;&amp; nums) {
    string ans = to_string(nums[0]);
    if (nums.size() == 1) return ans;
    else if (nums.size() == 2) return ans + "/" + to_string(nums[1]);
    
    ans += "/(" +  to_string(nums[1]);
    for (int i = 2; i &lt; nums.size(); ++i)
      ans += "/" + to_string(nums[i]);
    ans += ")";
    return ans;
  }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-553-optimal-division/">花花酱 LeetCode 553. Optimal Division</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-553-optimal-division/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
