3186. Maximum Total Damage With Spell Casting Medium
1/**
2 * [3186] Maximum Total Damage With Spell Casting
3 *
4 * A magician has various spells.
5 * You are given an array power, where each element represents the damage of a spell. Multiple spells can have the same damage value.
6 * It is a known fact that if a magician decides to cast a spell with a damage of power[i], they cannot cast any spell with a damage of power[i] - 2, power[i] - 1, power[i] + 1, or power[i] + 2.
7 * Each spell can be cast only once.
8 * Return the maximum possible total damage that a magician can cast.
9 *
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">power = [1,1,3,4]</span>
13 * Output: <span class="example-io">6</span>
14 * Explanation:
15 * The maximum possible damage of 6 is produced by casting spells 0, 1, 3 with damage 1, 1, 4.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">power = [7,1,6,6]</span>
20 * Output: <span class="example-io">13</span>
21 * Explanation:
22 * The maximum possible damage of 13 is produced by casting spells 1, 2, 3 with damage 1, 6, 6.
23 * </div>
24 *
25 * Constraints:
26 *
27 * 1 <= power.length <= 10^5
28 * 1 <= power[i] <= 10^9
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/maximum-total-damage-with-spell-casting/
34// discuss: https://leetcode.com/problems/maximum-total-damage-with-spell-casting/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn maximum_total_damage(power: Vec<i32>) -> i64 {
40
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_3186() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.