2
public int bagOfTokensScore(int[] tokens, int power) {3
// initially score is 0, that's why in these conditions, return 0.4
if (tokens.length == 0 || power < tokens[0]) return 0;5
Arrays.sort(tokens); // sort the array8
int r = tokens.length - 1;13
if (power >= tokens[i]) {15
answer = Math.max(answer, ++score); // play all tokens, but store the max score in answer.16
} else if (score > 0) {17
power += tokens[r--]; // take power from greatest element18
score--; // decrease by 1.20
// when you can't do any of the steps (face up, face down)