805. Split Array With Same Average Hard
1/**
2 * [805] Split Array With Same Average
3 *
4 * You are given an integer array nums.
5 * You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B).
6 * Return true if it is possible to achieve that and false otherwise.
7 * Note that for an array arr, average(arr) is the sum of all the elements of arr over the length of arr.
8 *
9 * Example 1:
10 *
11 * Input: nums = [1,2,3,4,5,6,7,8]
12 * Output: true
13 * Explanation: We can split the array into [1,4,5,8] and [2,3,6,7], and both of them have an average of 4.5.
14 *
15 * Example 2:
16 *
17 * Input: nums = [3,1]
18 * Output: false
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= nums.length <= 30
24 * 0 <= nums[i] <= 10^4
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/split-array-with-same-average/
30// discuss: https://leetcode.com/problems/split-array-with-same-average/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn split_array_same_average(nums: Vec<i32>) -> bool {
36 false
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_805() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.