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)/优美的排列 II [beautiful-arrangement-ii].html
2022-03-29 12:43:11 +08:00

36 lines
1.3 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>k</code> ,请你构造一个答案列表 <code>answer</code> ,该列表应当包含从 <code>1</code><code>n</code><code>n</code> 个不同正整数,并同时满足下述条件:</p>
<ul>
<li>假设该列表是 <code>answer = [a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>, ... , a<sub>n</sub>]</code> ,那么列表 <code>[|a<sub>1</sub> - a<sub>2</sub>|, |a<sub>2</sub> - a<sub>3</sub>|, |a<sub>3</sub> - a<sub>4</sub>|, ... , |a<sub>n-1</sub> - a<sub>n</sub>|]</code> 中应该有且仅有 <code>k</code> 个不同整数。</li>
</ul>
<p>返回列表 <code>answer</code> 。如果存在多种答案,只需返回其中 <strong>任意一种</strong></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 3, k = 1
<strong>输出:</strong>[1, 2, 3]
<strong>解释:</strong>[1, 2, 3] 包含 3 个范围在 1-3 的不同整数,并且 [1, 1] 中有且仅有 1 个不同整数1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 3, k = 2
<strong>输出:</strong>[1, 3, 2]
<strong>解释:</strong>[1, 3, 2] 包含 3 个范围在 1-3 的不同整数,并且 [2, 1] 中有且仅有 2 个不同整数1 和 2
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= k < n <= 10<sup>4</sup></code></li>
</ul>
<p> </p>