948.Bag of Tokens


You have an initial power P, an initial score of 0 points, and a bag of tokens.
给出一个有初始值权力值 P, 初始分数 0, 和一些令牌

Each token can be used at most once, has a value token[i], and has potentially two ways to use it.
每一个令牌都有自己的分值, 有两种方式使用, 但只能使用一次

  • If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point.
    如果我们的权力值大于任意令牌的分值, 我们可以打出这张牌, 获得 1 分值, 失去打出令牌所示的分值(P – token[i]).

  • If we have at least 1 point, we may play the token face down, gaining token[i] power, and losing 1 point.
    如果我们至少拥有 1 分值, 可以倒扣一张令牌, 获得其权力值(P + token[i]), 失去 1 分.

Return the largest number of points we can have after playing any number of tokens.
返回最大可能实现的 分值

Example 1:


尝试贪心, 尽可能获取更多的权力值, 而后通过权力值换分

Hello world!
文章已创建 200