1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/全局倒置与局部倒置 [global-and-local-inversions].html
2022-03-29 12:43:11 +08:00

47 lines
1.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个长度为 <code>n</code> 的整数数组 <code>nums</code> ,表示由范围 <code>[0, n - 1]</code> 内所有整数组成的一个排列。</p>
<p><strong>全局倒置</strong> 的数目等于满足下述条件不同下标对 <code>(i, j)</code> 的数目:</p>
<ul>
<li><code>0 <= i < j < n</code></li>
<li><code>nums[i] > nums[j]</code></li>
</ul>
<p><strong>局部倒置</strong> 的数目等于满足下述条件的下标 <code>i</code> 的数目:</p>
<ul>
<li><code>0 <= i < n - 1</code></li>
<li><code>nums[i] > nums[i + 1]</code></li>
</ul>
<p>当数组 <code>nums</code><strong>全局倒置</strong> 的数量等于 <strong>局部倒置</strong> 的数量时,返回 <code>true</code> ;否则,返回 <code>false</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,0,2]
<strong>输出:</strong>true
<strong>解释:</strong>有 1 个全局倒置,和 1 个局部倒置。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,0]
<strong>输出:</strong>false
<strong>解释:</strong>有 2 个全局倒置,和 1 个局部倒置。
</pre>
 
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 <= n <= 5000</code></li>
<li><code>0 <= nums[i] < n</code></li>
<li><code>nums</code> 中的所有整数 <strong>互不相同</strong></li>
<li><code>nums</code> 是范围 <code>[0, n - 1]</code> 内所有数字组成的一个排列</li>
</ul>