package leetcode;

/**
 * https://leetcode.com/problems/bag-of-tokens/
 */
public class Problem948 {
    public int bagOfTokensScore(int[] tokens, int P) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem948 prob = new Problem948();
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -187,38 +187,80 @@
     
-// TODO%0A        return
+Arrays.sort(tokens);%0A        int power = P;%0A        int points =
  0;%0A    
 %7D%0A%0A 
@@ -259,98 +259,500 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem948 prob = new Problem948()
+int left = 0;%0A        int right = tokens.length - 1;%0A        while (left %3C= right) %7B%0A            while (left %3C tokens.length && power - tokens%5Bleft%5D %3E= 0) %7B%0A                power -= tokens%5Bleft%5D;%0A                points++;%0A                left++;%0A            %7D%0A            if (left %3E= right %7C%7C points == 0) %7B%0A                break;%0A            %7D else %7B%0A                power += tokens%5Bright%5D;%0A                points--;%0A                right--;%0A            %7D%0A        %7D%0A        return points
 ;%0A  

Solve problem 948