918. Maximum Sum Circular Subarray Medium
1/**
2 * [918] Maximum Sum Circular Subarray
3 *
4 * Given a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums.
5 * A circular array means the end of the array connects to the beginning of the array. Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n].
6 * A subarray may only include each element of the fixed buffer nums at most once. Formally, for a subarray nums[i], nums[i + 1], ..., nums[j], there does not exist i <= k1, k2 <= j with k1 % n == k2 % n.
7 *
8 * Example 1:
9 *
10 * Input: nums = [1,-2,3,-2]
11 * Output: 3
12 * Explanation: Subarray [3] has maximum sum 3.
13 *
14 * Example 2:
15 *
16 * Input: nums = [5,-3,5]
17 * Output: 10
18 * Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10.
19 *
20 * Example 3:
21 *
22 * Input: nums = [-3,-2,-3]
23 * Output: -2
24 * Explanation: Subarray [-2] has maximum sum -2.
25 *
26 *
27 * Constraints:
28 *
29 * n == nums.length
30 * 1 <= n <= 3 * 10^4
31 * -3 * 10^4 <= nums[i] <= 3 * 10^4
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/maximum-sum-circular-subarray/
37// discuss: https://leetcode.com/problems/maximum-sum-circular-subarray/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn max_subarray_sum_circular(nums: Vec<i32>) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_918() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.