327. Count of Range Sum Hard
1/**
2 * [327] Count of Range Sum
3 *
4 * Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.
5 * Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j inclusive, where i <= j.
6 *
7 * Example 1:
8 *
9 * Input: nums = [-2,5,-1], lower = -2, upper = 2
10 * Output: 3
11 * Explanation: The three ranges are: [0,0], [2,2], and [0,2] and their respective sums are: -2, -1, 2.
12 *
13 * Example 2:
14 *
15 * Input: nums = [0], lower = 0, upper = 0
16 * Output: 1
17 *
18 *
19 * Constraints:
20 *
21 * 1 <= nums.length <= 10^5
22 * -2^31 <= nums[i] <= 2^31 - 1
23 * -10^5 <= lower <= upper <= 10^5
24 * The answer is guaranteed to fit in a 32-bit integer.
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/count-of-range-sum/
30// discuss: https://leetcode.com/problems/count-of-range-sum/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn count_range_sum(nums: Vec<i32>, lower: i32, upper: i32) -> i32 {
36 0
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_327() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.