Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 68cfe84

Browse files
Pramp problem
1 parent 63c064e commit 68cfe84

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎src/leetcode2018/Pramp.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package leetcode2018;
2+
3+
public class Pramp {
4+
public static void main(String[] args) {
5+
// TODO Auto-generated method stub
6+
System.out.println(findGrantsCap(new int[]{2, 100, 50, 120, 1000}, 190));
7+
}
8+
9+
static int findGrantsCap(int[] nums, int n){
10+
return helper(nums,n,0,false) ;
11+
}
12+
13+
static int helper(int[] nums, int n, int rest, boolean finish){
14+
if(finish){
15+
return 0;
16+
}
17+
int total=0;
18+
for(int i=0; i< nums.length;i++){
19+
if(nums[i]<= n/(nums.length-rest) && nums[i]!=-1){
20+
n-=nums[i];
21+
nums[i]=-1;
22+
rest++;
23+
total++;
24+
}
25+
}
26+
if(total==0) finish= true;
27+
helper(nums,n,rest, finish);
28+
int last=n/(nums.length-rest);
29+
return last;
30+
}
31+
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /