<?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>minmax_element Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/minmax_element/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/minmax_element/</link>
	<description></description>
	<lastBuildDate>Fri, 31 Dec 2021 23:17:24 +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>minmax_element Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/minmax_element/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1979. Find Greatest Common Divisor of Array</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-1979-find-greatest-common-divisor-of-array/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-1979-find-greatest-common-divisor-of-array/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Fri, 31 Dec 2021 23:16:50 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[gcd]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[minmax_element]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=9355</guid>

					<description><![CDATA[<p>Given an integer array&#160;nums, return&#160;the&#160;greatest common divisor&#160;of the smallest number and largest number in&#160;nums. The&#160;greatest common divisor&#160;of two numbers is the largest positive integer that&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-1979-find-greatest-common-divisor-of-array/">花花酱 LeetCode 1979. Find Greatest Common Divisor of Array</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 array&nbsp;<code>nums</code>, return<strong>&nbsp;</strong><em>the&nbsp;<strong>greatest common divisor</strong>&nbsp;of the smallest number and largest number in&nbsp;</em><code>nums</code>.</p>



<p>The&nbsp;<strong>greatest common divisor</strong>&nbsp;of two numbers is the largest positive integer that evenly divides both numbers.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> nums = [2,5,6,9,10]
<strong>Output:</strong> 2
<strong>Explanation:</strong>
The smallest number in nums is 2.
The largest number in nums is 10.
The greatest common divisor of 2 and 10 is 2.
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> nums = [7,5,6,8,3]
<strong>Output:</strong> 1
<strong>Explanation:</strong>
The smallest number in nums is 3.
The largest number in nums is 8.
The greatest common divisor of 3 and 8 is 1.
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> nums = [3,3]
<strong>Output:</strong> 3
<strong>Explanation:</strong>
The smallest number in nums is 3.
The largest number in nums is 3.
The greatest common divisor of 3 and 3 is 3.
</pre>



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



<ul><li><code>2 &lt;= nums.length &lt;= 1000</code></li><li><code>1 &lt;= nums[i] &lt;= 1000</code></li></ul>



<h2><strong>Solution:</strong></h2>



<p>Use <a href="https://en.cppreference.com/w/cpp/algorithm/minmax_element" target="_blank" rel="noreferrer noopener">std::minmax_element</a> and <a href="https://en.cppreference.com/w/cpp/numeric/gcd" target="_blank" rel="noreferrer noopener">std::gcd</a></p>



<p>Time complexity: O(n)<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 findGCD(vector&lt;int&gt;&amp; nums) {
    auto p = minmax_element(begin(nums), end(nums));     
    return gcd(*p.first, *p.second);
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-1979-find-greatest-common-divisor-of-array/">花花酱 LeetCode 1979. Find Greatest Common Divisor of Array</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-1979-find-greatest-common-divisor-of-array/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
