mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-24 22:38:57 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个整数数组 <code>nums</code> 。请你对数组执行下述操作:</p>\n\n<ol>\n\t<li>从 <code>nums</code> 中找出 <strong>任意</strong> 两个 <strong>相邻</strong> 的 <strong>非互质</strong> 数。</li>\n\t<li>如果不存在这样的数,<strong>终止</strong> 这一过程。</li>\n\t<li>否则,删除这两个数,并 <strong>替换</strong> 为它们的 <strong>最小公倍数</strong>(Least Common Multiple,LCM)。</li>\n\t<li>只要还能找出两个相邻的非互质数就继续 <strong>重复</strong> 这一过程。</li>\n</ol>\n\n<p>返回修改后得到的 <strong>最终</strong> 数组。可以证明的是,以 <strong>任意</strong> 顺序替换相邻的非互质数都可以得到相同的结果。</p>\n\n<p>生成的测试用例可以保证最终数组中的值 <strong>小于或者等于</strong> <code>10<sup>8</sup></code> 。</p>\n\n<p>两个数字 <code>x</code> 和 <code>y</code> 满足 <strong>非互质数</strong> 的条件是:<code>GCD(x, y) > 1</code> ,其中 <code>GCD(x, y)</code> 是 <code>x</code> 和 <code>y</code> 的 <strong>最大公约数</strong> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1 :</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [6,4,3,2,7,6,2]\n<strong>输出:</strong>[12,7,6]\n<strong>解释:</strong>\n- (6, 4) 是一组非互质数,且 LCM(6, 4) = 12 。得到 nums = [<em><strong>12</strong></em>,3,2,7,6,2] 。\n- (12, 3) 是一组非互质数,且 LCM(12, 3) = 12 。得到 nums = [<em><strong>12</strong></em>,2,7,6,2] 。\n- (12, 2) 是一组非互质数,且 LCM(12, 2) = 12 。得到 nums = [<em><strong>12</strong></em>,7,6,2] 。\n- (6, 2) 是一组非互质数,且 LCM(6, 2) = 6 。得到 nums = [12,7,<em><strong>6</strong></em>] 。\n现在,nums 中不存在相邻的非互质数。\n因此,修改后得到的最终数组是 [12,7,6] 。\n注意,存在其他方法可以获得相同的最终数组。\n</pre>\n\n<p><strong>示例 2 :</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [2,2,1,1,3,3,3]\n<strong>输出:</strong>[2,1,1,3]\n<strong>解释:</strong>\n- (3, 3) 是一组非互质数,且 LCM(3, 3) = 3 。得到 nums = [2,2,1,1,<em><strong>3</strong></em>,3] 。\n- (3, 3) 是一组非互质数,且 LCM(3, 3) = 3 。得到 nums = [2,2,1,1,<em><strong>3</strong></em>] 。\n- (2, 2) 是一组非互质数,且 LCM(2, 2) = 2 。得到 nums = [<em><strong>2</strong></em>,1,1,3] 。\n现在,nums 中不存在相邻的非互质数。 \n因此,修改后得到的最终数组是 [2,1,1,3] 。 \n注意,存在其他方法可以获得相同的最终数组。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>\n\t<li>生成的测试用例可以保证最终数组中的值 <strong>小于或者等于</strong> <code>10<sup>8</sup></code> 。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 24,
|
||||
"likes": 25,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"4.5K\", \"totalSubmission\": \"13.8K\", \"totalAcceptedRaw\": 4479, \"totalSubmissionRaw\": 13805, \"acRate\": \"32.4%\"}",
|
||||
"stats": "{\"totalAccepted\": \"4.6K\", \"totalSubmission\": \"14.1K\", \"totalAcceptedRaw\": 4623, \"totalSubmissionRaw\": 14096, \"acRate\": \"32.8%\"}",
|
||||
"hints": [
|
||||
"Notice that the order of merging two numbers into their LCM does not matter so we can greedily merge elements to its left if possible.",
|
||||
"If a new value is formed, we should recursively check if it can be merged with the value to its left.",
|
||||
|
||||
Reference in New Issue
Block a user