1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
程序员小墨 2022-10-26 20:38:53 +08:00
parent 396e839079
commit 193158abb0
25 changed files with 14351 additions and 12051 deletions

View File

@ -1,6 +1,6 @@
# 力扣题库(完整版)
> 最后更新日期: **2022.10.20**
> 最后更新日期: **2022.10.26**
>
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,53 @@
<p>给你两个正整数数组&nbsp;<code>nums</code>&nbsp;<code>target</code>&nbsp;,两个数组长度相等。</p>
<p>在一次操作中,你可以选择两个 <strong>不同</strong>&nbsp;的下标&nbsp;<code>i</code>&nbsp;<code>j</code>&nbsp;,其中&nbsp;<code>0 &lt;= i, j &lt; nums.length</code>&nbsp;,并且:</p>
<ul>
<li>&nbsp;<code>nums[i] = nums[i] + 2</code>&nbsp;</li>
<li>&nbsp;<code>nums[j] = nums[j] - 2</code>&nbsp;</li>
</ul>
<p>如果两个数组中每个元素出现的频率相等,我们称两个数组是 <strong>相似</strong>&nbsp;的。</p>
<p>请你返回将 <code>nums</code>&nbsp;变得与 <code>target</code>&nbsp;相似的最少操作次数。测试数据保证 <code>nums</code>&nbsp;一定能变得与 <code>target</code>&nbsp;相似。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [8,12,6], target = [2,14,10]
<b>输出:</b>2
<b>解释:</b>可以用两步操作将 nums 变得与 target 相似:
- 选择 i = 0 和 j = 2 nums = [10,12,4] 。
- 选择 i = 1 和 j = 2 nums = [10,14,2] 。
2 次操作是最少需要的操作次数。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [1,2,5], target = [4,1,3]
<b>输出:</b>1
<b>解释:</b>一步操作可以使 nums 变得与 target 相似:
- 选择 i = 1 和 j = 2 nums = [1,4,3] 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>nums = [1,1,1,1,1], target = [1,1,1,1,1]
<b>输出:</b>0
<b>解释:</b>数组 nums 已经与 target 相似。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length == target.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], target[i] &lt;= 10<sup>6</sup></code></li>
<li><code>nums</code>&nbsp;一定可以变得与&nbsp;<code>target</code> 相似。</li>
</ul>

View File

@ -0,0 +1,42 @@
<p>给你两个下标从 <strong>0</strong>&nbsp;开始的数组&nbsp;<code>nums</code>&nbsp;<code>cost</code>&nbsp;,分别包含&nbsp;<code>n</code>&nbsp;&nbsp;<strong></strong>&nbsp;整数。</p>
<p>你可以执行下面操作 <strong>任意</strong>&nbsp;次:</p>
<ul>
<li>&nbsp;<code>nums</code>&nbsp;<strong>任意</strong>&nbsp;元素增加或者减小 <code>1</code>&nbsp;</li>
</ul>
<p>对第 <code>i</code>&nbsp;个元素执行一次操作的开销是&nbsp;<code>cost[i]</code>&nbsp;</p>
<p>请你返回使 <code>nums</code>&nbsp;中所有元素 <strong>相等</strong>&nbsp;<strong>最少</strong>&nbsp;总开销。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [1,3,5,2], cost = [2,3,1,14]
<b>输出:</b>8
<b>解释:</b>我们可以执行以下操作使所有元素变为 2
- 增加第 0 个元素 1 次,开销为 2 。
- 减小第 1 个元素 1 次,开销为 3 。
- 减小第 2 个元素 3 次,开销为 1 + 1 + 1 = 3 。
总开销为 2 + 3 + 3 = 8 。
这是最小开销。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [2,2,2,2,2], cost = [4,2,8,1,3]
<b>输出:</b>0
<b>解释:</b>数组中所有元素已经全部相等,不需要执行额外的操作。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length == cost.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], cost[i] &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,50 @@
<p>给你两个字符串数组 <code>event1</code>&nbsp;<code>event2</code>&nbsp;,表示发生在同一天的两个闭区间时间段事件,其中:</p>
<ul>
<li><code>event1 = [startTime<sub>1</sub>, endTime<sub>1</sub>]</code></li>
<li><code>event2 = [startTime<sub>2</sub>, endTime<sub>2</sub>]</code></li>
</ul>
<p>事件的时间为有效的 24 小时制且按&nbsp;<code>HH:MM</code>&nbsp;格式给出。</p>
<p>当两个事件存在某个非空的交集时(即,某些时刻是两个事件都包含的),则认为出现 <strong>冲突</strong>&nbsp;</p>
<p>如果两个事件之间存在冲突,返回&nbsp;<code>true</code><em>&nbsp;</em>;否则,返回<em>&nbsp;</em><code>false</code></p>
<p>&nbsp;</p>
<p><b>示例 1</b></p>
<pre>
<b>输入:</b>event1 = ["01:15","02:00"], event2 = ["02:00","03:00"]
<b>输出:</b>true
<b>解释:</b>两个事件在 2:00 出现交集。
</pre>
<p><b>示例 2</b></p>
<pre>
<b>输入:</b>event1 = ["01:00","02:00"], event2 = ["01:20","03:00"]
<b>输出:</b>true
<b>解释:</b>两个事件的交集从 01:20 开始,到 02:00 结束。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>event1 = ["10:00","11:00"], event2 = ["14:00","15:00"]
<b>输出:</b>false
<b>解释:</b>两个事件不存在交集。
</pre>
<p>&nbsp;</p>
<p><b>提示:</b></p>
<ul>
<li><code>evnet1.length == event2.length == 2.</code></li>
<li><code>event1[i].length == event2[i].length == 5</code></li>
<li><code>startTime<sub>1</sub> &lt;= endTime<sub>1</sub></code></li>
<li><code>startTime<sub>2</sub> &lt;= endTime<sub>2</sub></code></li>
<li>所有事件的时间都按照&nbsp;<code>HH:MM</code>&nbsp;格式给出</li>
</ul>

View File

@ -0,0 +1,34 @@
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code> ,请你统计并返回 <code>nums</code>&nbsp;的子数组中元素的最大公因数等于 <code>k</code>&nbsp;的子数组数目。</p>
<p><strong>子数组</strong> 是数组中一个连续的非空序列。</p>
<p><strong>数组的最大公因数</strong>&nbsp;是能整除数组中所有元素的最大整数。</p>
<p>&nbsp;</p>
<p><b>示例 1</b></p>
<pre><b>输入:</b>nums = [9,3,1,2,6,3], k = 3
<b>输出:</b>4
<b>解释:</b>nums 的子数组中,以 3 作为最大公因数的子数组如下:
- [9,<strong><em>3</em></strong>,1,2,6,3]
- [9,3,1,2,6,<em><strong>3</strong></em>]
- [<strong><em>9,3</em></strong>,1,2,6,3]
- [9,3,1,2,<em><strong>6,3</strong></em>]
</pre>
<p><b>示例 2</b></p>
<pre><b>输入:</b>nums = [4], k = 7
<b>输出:</b>0
<b>解释:</b>不存在以 7 作为最大公因数的子数组。
</pre>
<p>&nbsp;</p>
<p><b>提示:</b></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i], k &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,51 @@
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p>
<p>In one operation, you can choose any two <strong>distinct</strong> indices <code>i</code> and <code>j</code> where <code>0 &lt;= i, j &lt; nums.length</code> and:</p>
<ul>
<li>set <code>nums[i] = nums[i] + 2</code> and</li>
<li>set <code>nums[j] = nums[j] - 2</code>.</li>
</ul>
<p>Two arrays are considered to be <strong>similar</strong> if the frequency of each element is the same.</p>
<p>Return <em>the minimum number of operations required to make </em><code>nums</code><em> similar to </em><code>target</code>. The test cases are generated such that <code>nums</code> can always be similar to <code>target</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [8,12,6], target = [2,14,10]
<strong>Output:</strong> 2
<strong>Explanation:</strong> It is possible to make nums similar to target in two operations:
- Choose i = 0 and j = 2, nums = [10,12,4].
- Choose i = 1 and j = 2, nums = [10,14,2].
It can be shown that 2 is the minimum number of operations needed.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,5], target = [4,1,3]
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can make nums similar to target in one operation:
- Choose i = 1 and j = 2, nums = [1,4,3].
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,1,1,1], target = [1,1,1,1,1]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The array nums is already similiar to target.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length == target.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], target[i] &lt;= 10<sup>6</sup></code></li>
<li>It is possible to make <code>nums</code> similar to <code>target</code>.</li>
</ul>

View File

@ -0,0 +1,42 @@
<p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the array <code>nums</code> by <code>1</code>.</li>
</ul>
<p>The cost of doing one operation on the <code>i<sup>th</sup></code> element is <code>cost[i]</code>.</p>
<p>Return <em>the <strong>minimum</strong> total cost such that all the elements of the array </em><code>nums</code><em> become <strong>equal</strong></em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,3,5,2], cost = [2,3,1,14]
<strong>Output:</strong> 8
<strong>Explanation:</strong> We can make all the elements equal to 2 in the following way:
- Increase the 0<sup>th</sup> element one time. The cost is 2.
- Decrease the 1<sup><span style="font-size: 10.8333px;">st</span></sup> element one time. The cost is 3.
- Decrease the 2<sup>nd</sup> element three times. The cost is 1 + 1 + 1 = 3.
The total cost is 2 + 3 + 3 = 8.
It can be shown that we cannot make the array equal with a smaller cost.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [2,2,2,2,2], cost = [4,2,8,1,3]
<strong>Output:</strong> 0
<strong>Explanation:</strong> All the elements are already equal, so no operations are needed.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length == cost.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], cost[i] &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,48 @@
<p>You are given two arrays of strings that represent two inclusive events that happened <strong>on the same day</strong>, <code>event1</code> and <code>event2</code>, where:</p>
<ul>
<li><code>event1 = [startTime<sub>1</sub>, endTime<sub>1</sub>]</code> and</li>
<li><code>event2 = [startTime<sub>2</sub>, endTime<sub>2</sub>]</code>.</li>
</ul>
<p>Event times are valid 24 hours format in the form of <code>HH:MM</code>.</p>
<p>A <strong>conflict</strong> happens when two events have some non-empty intersection (i.e., some moment is common to both events).</p>
<p>Return <code>true</code><em> if there is a conflict between two events. Otherwise, return </em><code>false</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> event1 = [&quot;01:15&quot;,&quot;02:00&quot;], event2 = [&quot;02:00&quot;,&quot;03:00&quot;]
<strong>Output:</strong> true
<strong>Explanation:</strong> The two events intersect at time 2:00.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> event1 = [&quot;01:00&quot;,&quot;02:00&quot;], event2 = [&quot;01:20&quot;,&quot;03:00&quot;]
<strong>Output:</strong> true
<strong>Explanation:</strong> The two events intersect starting from 01:20 to 02:00.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> event1 = [&quot;10:00&quot;,&quot;11:00&quot;], event2 = [&quot;14:00&quot;,&quot;15:00&quot;]
<strong>Output:</strong> false
<strong>Explanation:</strong> The two events do not intersect.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>evnet1.length == event2.length == 2.</code></li>
<li><code>event1[i].length == event2[i].length == 5</code></li>
<li><code>startTime<sub>1</sub> &lt;= endTime<sub>1</sub></code></li>
<li><code>startTime<sub>2</sub> &lt;= endTime<sub>2</sub></code></li>
<li>All the event times follow the <code>HH:MM</code> format.</li>
</ul>

View File

@ -0,0 +1,34 @@
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the number of <strong>subarrays</strong> of </em><code>nums</code><em> where the greatest common divisor of the subarray&#39;s elements is </em><code>k</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p>The <strong>greatest common divisor of an array</strong> is the largest integer that evenly divides all the array elements.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [9,3,1,2,6,3], k = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> The subarrays of nums where 3 is the greatest common divisor of all the subarray&#39;s elements are:
- [9,<u><strong>3</strong></u>,1,2,6,3]
- [9,3,1,2,6,<u><strong>3</strong></u>]
- [<u><strong>9,3</strong></u>,1,2,6,3]
- [9,3,1,2,<u><strong>6,3</strong></u>]
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [4], k = 7
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no subarrays of nums where 7 is the greatest common divisor of all the subarray&#39;s elements.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i], k &lt;= 10<sup>9</sup></code></li>
</ul>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,48 @@
<p>You are given two arrays of strings that represent two inclusive events that happened <strong>on the same day</strong>, <code>event1</code> and <code>event2</code>, where:</p>
<ul>
<li><code>event1 = [startTime<sub>1</sub>, endTime<sub>1</sub>]</code> and</li>
<li><code>event2 = [startTime<sub>2</sub>, endTime<sub>2</sub>]</code>.</li>
</ul>
<p>Event times are valid 24 hours format in the form of <code>HH:MM</code>.</p>
<p>A <strong>conflict</strong> happens when two events have some non-empty intersection (i.e., some moment is common to both events).</p>
<p>Return <code>true</code><em> if there is a conflict between two events. Otherwise, return </em><code>false</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> event1 = [&quot;01:15&quot;,&quot;02:00&quot;], event2 = [&quot;02:00&quot;,&quot;03:00&quot;]
<strong>Output:</strong> true
<strong>Explanation:</strong> The two events intersect at time 2:00.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> event1 = [&quot;01:00&quot;,&quot;02:00&quot;], event2 = [&quot;01:20&quot;,&quot;03:00&quot;]
<strong>Output:</strong> true
<strong>Explanation:</strong> The two events intersect starting from 01:20 to 02:00.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> event1 = [&quot;10:00&quot;,&quot;11:00&quot;], event2 = [&quot;14:00&quot;,&quot;15:00&quot;]
<strong>Output:</strong> false
<strong>Explanation:</strong> The two events do not intersect.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>evnet1.length == event2.length == 2.</code></li>
<li><code>event1[i].length == event2[i].length == 5</code></li>
<li><code>startTime<sub>1</sub> &lt;= endTime<sub>1</sub></code></li>
<li><code>startTime<sub>2</sub> &lt;= endTime<sub>2</sub></code></li>
<li>All the event times follow the <code>HH:MM</code> format.</li>
</ul>

View File

@ -0,0 +1,42 @@
<p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the array <code>nums</code> by <code>1</code>.</li>
</ul>
<p>The cost of doing one operation on the <code>i<sup>th</sup></code> element is <code>cost[i]</code>.</p>
<p>Return <em>the <strong>minimum</strong> total cost such that all the elements of the array </em><code>nums</code><em> become <strong>equal</strong></em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,3,5,2], cost = [2,3,1,14]
<strong>Output:</strong> 8
<strong>Explanation:</strong> We can make all the elements equal to 2 in the following way:
- Increase the 0<sup>th</sup> element one time. The cost is 2.
- Decrease the 1<sup><span style="font-size: 10.8333px;">st</span></sup> element one time. The cost is 3.
- Decrease the 2<sup>nd</sup> element three times. The cost is 1 + 1 + 1 = 3.
The total cost is 2 + 3 + 3 = 8.
It can be shown that we cannot make the array equal with a smaller cost.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [2,2,2,2,2], cost = [4,2,8,1,3]
<strong>Output:</strong> 0
<strong>Explanation:</strong> All the elements are already equal, so no operations are needed.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length == cost.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], cost[i] &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,51 @@
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p>
<p>In one operation, you can choose any two <strong>distinct</strong> indices <code>i</code> and <code>j</code> where <code>0 &lt;= i, j &lt; nums.length</code> and:</p>
<ul>
<li>set <code>nums[i] = nums[i] + 2</code> and</li>
<li>set <code>nums[j] = nums[j] - 2</code>.</li>
</ul>
<p>Two arrays are considered to be <strong>similar</strong> if the frequency of each element is the same.</p>
<p>Return <em>the minimum number of operations required to make </em><code>nums</code><em> similar to </em><code>target</code>. The test cases are generated such that <code>nums</code> can always be similar to <code>target</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [8,12,6], target = [2,14,10]
<strong>Output:</strong> 2
<strong>Explanation:</strong> It is possible to make nums similar to target in two operations:
- Choose i = 0 and j = 2, nums = [10,12,4].
- Choose i = 1 and j = 2, nums = [10,14,2].
It can be shown that 2 is the minimum number of operations needed.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,5], target = [4,1,3]
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can make nums similar to target in one operation:
- Choose i = 1 and j = 2, nums = [1,4,3].
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,1,1,1], target = [1,1,1,1,1]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The array nums is already similiar to target.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length == target.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], target[i] &lt;= 10<sup>6</sup></code></li>
<li>It is possible to make <code>nums</code> similar to <code>target</code>.</li>
</ul>

View File

@ -0,0 +1,34 @@
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the number of <strong>subarrays</strong> of </em><code>nums</code><em> where the greatest common divisor of the subarray&#39;s elements is </em><code>k</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p>The <strong>greatest common divisor of an array</strong> is the largest integer that evenly divides all the array elements.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [9,3,1,2,6,3], k = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> The subarrays of nums where 3 is the greatest common divisor of all the subarray&#39;s elements are:
- [9,<u><strong>3</strong></u>,1,2,6,3]
- [9,3,1,2,6,<u><strong>3</strong></u>]
- [<u><strong>9,3</strong></u>,1,2,6,3]
- [9,3,1,2,<u><strong>6,3</strong></u>]
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [4], k = 7
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no subarrays of nums where 7 is the greatest common divisor of all the subarray&#39;s elements.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i], k &lt;= 10<sup>9</sup></code></li>
</ul>