-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5.java
More file actions
57 lines (54 loc) · 1.23 KB
/
Copy pathday5.java
File metadata and controls
57 lines (54 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ques 1 : 2591. Distribute money to maximum children
// Link : https://leetcode.com/problems/distribute-money-to-maximum-children/description/?envType=problem-list-v2&envId=math
class Solution {
public int distMoney(int money, int children) {
int n=children;
int m=money;
int x=m/8;
if(m<n)
return -1;
else if(m-7<n)
return 0;
if(n<x){
if(n-1<=0)
return 0;
else
return n-1;}
else if(n==x){
if(m%8==0){
if(x<=0)
return 0;
else
return x;
}
else{
if(x-1<=0)
return 0;
else
return x-1;
}
}
else if(n>x){
if(m%8==4 && n==x+1)
{
if(x-1<=0)
return 0;
else
return x-1;
}
else if(n-x<=m%8)
if(x<=0)
return 0;
else
return x;
for(int i=0;i<=x;i++){
if( n-x-m%8 <= i*7)
if(x-i<=0)
return 0;
else
return x-i;
}
}
return 0;
}
}