Skip to content

Latest commit

 

History

History
79 lines (45 loc) · 1.58 KB

3186-maximum-total-damage-with-spell-casting.adoc

File metadata and controls

79 lines (45 loc) · 1.58 KB

3186. Maximum Total Damage With Spell Casting

{leetcode}/problems/maximum-total-damage-with-spell-casting/[LeetCode - 3186. Maximum Total Damage With Spell Casting ^]

A magician has various spells.

You are given an array power, where each element represents the damage of a spell. Multiple spells can have the same damage value.

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.

Each spell can be cast only once.

Return the maximum possible total damage that a magician can cast.

Example 1:

<div class="example-block"> Input: <span class="example-io">power = [1,1,3,4]

Output: <span class="example-io">6

Explanation:

The maximum possible damage of 6 is produced by casting spells 0, 1, 3 with damage 1, 1, 4.

Example 2:

<div class="example-block"> Input: <span class="example-io">power = [7,1,6,6]

Output: <span class="example-io">13

Explanation:

The maximum possible damage of 13 is produced by casting spells 1, 2, 3 with damage 1, 6, 6.

Constraints:

  • 1 ⇐ power.length ⇐ 105

  • 1 ⇐ power[i] ⇐ 109

思路分析

一刷
link:{sourcedir}/_3186_MaximumTotalDamageWithSpellCasting.java[role=include]

参考资料