1262. Greatest Sum Divisible by Three Medium

@problem@discussion
#Array#Dynamic Programming#Greedy



1/**
2 * [1262] Greatest Sum Divisible by Three
3 *
4 * Given an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three.
5 *  
6 * Example 1:
7 * 
8 * Input: nums = [3,6,5,1,8]
9 * Output: 18
10 * Explanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3).
11 * Example 2:
12 * 
13 * Input: nums = [4]
14 * Output: 0
15 * Explanation: Since 4 is not divisible by 3, do not pick any number.
16 * 
17 * Example 3:
18 * 
19 * Input: nums = [1,2,3,4,4]
20 * Output: 12
21 * Explanation: Pick numbers 1, 3, 4 and 4 their sum is 12 (maximum sum divisible by 3).
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	1 <= nums.length <= 4 * 10^4
27 * 	1 <= nums[i] <= 10^4
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/greatest-sum-divisible-by-three/
33// discuss: https://leetcode.com/problems/greatest-sum-divisible-by-three/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn max_sum_div_three(nums: Vec<i32>) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_1262() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.