|
1 | 1 | classSolution {
|
2 |
| -publicdoublechampagneTower(intpoured,intquery_row,intquery_glass) { |
3 |
| -double[][]glassCapacity =newdouble[query_row +1][query_glass +2]; |
4 |
| -glassCapacity[0][0] =poured; |
5 |
| -for (intcurrRow =0;currRow <query_row;currRow++) { |
6 |
| -for (intcurrCol =0;currCol <=query_glass;currCol++) { |
7 |
| -doublecurrCapacity =Math.max(glassCapacity[currRow][currCol] -1.0,0); |
8 |
| -glassCapacity[currRow +1][currCol] +=currCapacity /2.0; |
9 |
| -glassCapacity[currRow +1][currCol +1] +=currCapacity /2.0; |
10 |
| - } |
| 2 | +publicdoublechampagneTower(intpoured,intquery_row,intquery_glass) { |
| 3 | +double[]glass =newdouble[query_row +2]; |
| 4 | +glass[0] =poured; |
| 5 | +for (introw =1;row <=query_row;row++) { |
| 6 | +for (intidx =row;idx >=0;idx--) { |
| 7 | +glass[idx] =Math.max(0.0, (glass[idx] -1) /2); |
| 8 | +glass[idx +1] +=glass[idx]; |
| 9 | + } |
| 10 | + } |
| 11 | +returnMath.min(glass[query_glass],1.0); |
11 | 12 | }
|
12 |
| -returnMath.min(glassCapacity[query_row][query_glass],1.0); |
13 |
| - } |
14 | 13 | }
|