Skip to content

Commit cc4fda5

Browse files
authored
updated
proper spacing
1 parent a92743c commit cc4fda5

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Dynamic Programming/EggDropping.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ private static int minTrials(int n, int m)
1313
for (int i = 1; i <= n; i++)
1414
{
1515
eggFloor[i][0] = 0; // Zero trial for zero floor.
16-
eggFloor[i][1] = 1; // One trial for one floor
16+
eggFloor[i][1] = 1; // One trial for one floor
1717
}
1818

19-
// j trials for only 1 egg
19+
// j trials for only 1 egg
2020

21-
for (int j = 1; j <= m; j++)
21+
for (int j = 1; j <= m; j++)
2222
eggFloor[1][j] = j;
2323

2424
// Using bottom-up approach in DP
2525

26-
for (int i = 2; i <= n; i++)
27-
{
26+
for (int i = 2; i <= n; i++)
27+
{
2828
for (int j = 2; j <= m; j++)
2929
{
3030
eggFloor[i][j] = Integer.MAX_VALUE;
@@ -33,22 +33,21 @@ private static int minTrials(int n, int m)
3333
result = 1 + Math.max(eggFloor[i-1][x-1], eggFloor[i][j-x]);
3434

3535
//choose min of all values for particular x
36-
if (result < eggFloor[i][j])
37-
eggFloor[i][j] = result;
36+
if (result < eggFloor[i][j])
37+
eggFloor[i][j] = result;
3838
}
3939
}
4040
}
41+
4142
return eggFloor[n][m];
42-
4343
}
4444

4545
//testing program
4646
public static void main(String args[])
4747
{
48-
int n = 2, m = 4;
49-
//result outputs min no. of trials in worst case for n eggs and m floors
50-
51-
int result = minTrials(n, m);
52-
System.out.println(result);
48+
int n = 2, m = 4;
49+
//result outputs min no. of trials in worst case for n eggs and m floors
50+
int result = minTrials(n, m);
51+
System.out.println(result);
5352
}
5453
}

0 commit comments

Comments
 (0)