Skip to content

Latest commit

 

History

History
135 lines (53 loc) · 1.93 KB

File metadata and controls

135 lines (53 loc) · 1.93 KB

中文文档

Description

You have an initial power P, an initial score of 0 points, and a bag of tokens.

Each token can be used at most once, has a value token[i], and has potentially two ways to use it.

    <li>If we have at least <code>token[i]</code> power, we may play the token face up, losing <code>token[i]</code> power, and gaining <code>1</code> point.</li>
    
    <li>If we have at least <code>1</code> point, we may play the token face down, gaining <code>token[i]</code> power, and losing <code>1</code> point.</li>
    

Return the largest number of points we can have after playing any number of tokens.

 

Example 1:

Input: tokens = [100], P = 50

Output: 0

Example 2:

Input: tokens = [100,200], P = 150

Output: 1

Example 3:

Input: tokens = [100,200,300,400], P = 200

Output: 2

 

Note:

    <li><code>tokens.length &lt;= 1000</code></li>
    
    <li><code>0 &lt;= tokens[i] &lt; 10000</code></li>
    
    <li><code>0 &lt;= P &lt; 10000</code></li>
    

Solutions

Python3

Java

...