932. Beautiful Array Medium
1/**
2 * [932] Beautiful Array
3 *
4 * An array nums of length n is beautiful if:
5 *
6 * nums is a permutation of the integers in the range [1, n].
7 * For every 0 <= i < j < n, there is no index k with i < k < j where 2 * nums[k] == nums[i] + nums[j].
8 *
9 * Given the integer n, return any beautiful array nums of length n. There will be at least one valid answer for the given n.
10 *
11 * Example 1:
12 * Input: n = 4
13 * Output: [2,1,4,3]
14 * Example 2:
15 * Input: n = 5
16 * Output: [3,1,2,5,4]
17 *
18 * Constraints:
19 *
20 * 1 <= n <= 1000
21 *
22 */
23pub struct Solution {}
24
25// problem: https://leetcode.com/problems/beautiful-array/
26// discuss: https://leetcode.com/problems/beautiful-array/discuss/?currentPage=1&orderBy=most_votes&query=
27
28// submission codes start here
29
30impl Solution {
31 pub fn beautiful_array(n: i32) -> Vec<i32> {
32 vec![]
33 }
34}
35
36// submission codes end
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn test_932() {
44 }
45}
46
Back
© 2025 bowen.ge All Rights Reserved.