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)/统计作战单位数 [count-number-of-teams].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> 名士兵站成一排。每个士兵都有一个 <strong>独一无二</strong> 的评分 <code>rating</code></p>
<p><strong>3</strong> 个士兵可以组成一个作战单位,分组规则如下:</p>
<ul>
<li>从队伍中选出下标分别为 <code>i</code><code>j</code><code>k</code> 的 3 名士兵,他们的评分分别为 <code>rating[i]</code><code>rating[j]</code><code>rating[k]</code></li>
<li>作战单位需满足: <code>rating[i] < rating[j] < rating[k]</code> 或者 <code>rating[i] > rating[j] > rating[k]</code> ,其中  <code>0 <= i < j < k < n</code></li>
</ul>
<p>请你返回按上述条件可以组建的作战单位数量。每个士兵都可以是多个作战单位的一部分。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>rating = [2,5,3,4,1]
<strong>输出:</strong>3
<strong>解释:</strong>我们可以组建三个作战单位 (2,3,4)、(5,4,1)、(5,3,1) 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>rating = [2,1,3]
<strong>输出:</strong>0
<strong>解释:</strong>根据题目条件,我们无法组建作战单位。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>rating = [1,2,3,4]
<strong>输出:</strong>4
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == rating.length</code></li>
<li><code>3 <= n <= 1000</code></li>
<li><code>1 <= rating[i] <= 10^5</code></li>
<li><code>rating</code> 中的元素都是唯一的</li>
</ul>