Skip to content

Commit 5d86d26

Browse files
committed
Adjust RandomizedSet solution for readability
1 parent 7903ff1 commit 5d86d26

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/main/java/by/andd3dfx/collections/RandomizedSet.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ public boolean remove(int val) {
6868
var isExist = map.containsKey(val);
6969
if (isExist) {
7070
var index = map.get(val);
71-
values.set(index, values.getLast());
72-
map.put(values.get(index), index);
71+
72+
var lastValue = values.getLast();
73+
values.set(index, lastValue);
74+
map.put(lastValue, index);
75+
7376
values.removeLast();
7477
map.remove(val);
7578
}

0 commit comments

Comments
 (0)