Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BoxesOfBooks {
- public static int boxes (int []weights, int maxWeight) {
- int tot=0;
- int weightleft=maxWeight;
- for (int i=0; i<weights.length; i++) {
- //System.out.println(weightleft);
- if (weights[i]<=weightleft) {
- weightleft=weightleft-weights[i];
- }
- else if (weights[i]>weightleft) {
- tot++;
- weightleft=10;
- weightleft=weightleft-weights[i];
- }
- }
- return tot+1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement