File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
src/main/java/org/zjy/learn/code/amazon Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -64,22 +64,26 @@ private List<List<Integer>> optimalUtilization(
64
64
list .add (pair .get (0 ));
65
65
tree .put (pair .get (1 ), list );
66
66
}
67
- TreeMap <Integer , List <List <Integer >>> result = new TreeMap <>();
67
+ int diff = Integer .MAX_VALUE ;
68
+ List <List <Integer >> result = new ArrayList <>();
68
69
for (List <Integer > pair : foregroundAppList ) {
69
70
Integer floorKey = tree .floorKey (deviceCapacity - pair .get (1 ));
70
71
if (floorKey != null ) {
71
- int diff = Math .abs (deviceCapacity - pair .get (1 ) - floorKey );
72
- List <List <Integer >> list = result .getOrDefault (diff , new ArrayList <>());
72
+ if (Math .abs (deviceCapacity - pair .get (1 ) - floorKey ) < diff ) {
73
+ result .clear ();
74
+ diff = Math .abs (deviceCapacity - pair .get (1 ) - floorKey );
75
+ } else if (Math .abs (deviceCapacity - pair .get (1 ) - floorKey ) > diff ) {
76
+ continue ;
77
+ }
73
78
for (int id : tree .get (floorKey )) {
74
79
List <Integer > match = new ArrayList <>();
75
80
match .add (pair .get (0 ));
76
81
match .add (id );
77
- list .add (match );
82
+ result .add (match );
78
83
}
79
- result .put (diff , list );
80
84
}
81
85
}
82
- return result . get ( result . firstKey ()) ;
86
+ return result ;
83
87
}
84
88
85
89
private void output (List <List <Integer >> matrix ) {
You can’t perform that action at this time.
0 commit comments