filmov
tv
30 min Java Coding Challenge - Insert Delete GetRandom()

Показать описание
class RandomizedSet {
Map[Integer, Integer] table;
List[Integer] randomList;
/** Initialize your data structure here. */
public RandomizedSet() {
}
/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */
public boolean insert(int val) {
return false;
return true;
}
/** Removes a value from the set. Returns true if the set contained the specified element. */
public boolean remove(int val) {
return false;
}
return true;
}
/** Get a random element from the set. */
public int getRandom() {
if(len == 0)
return 0;
Random rand = new Random();
}
}
Map[Integer, Integer] table;
List[Integer] randomList;
/** Initialize your data structure here. */
public RandomizedSet() {
}
/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */
public boolean insert(int val) {
return false;
return true;
}
/** Removes a value from the set. Returns true if the set contained the specified element. */
public boolean remove(int val) {
return false;
}
return true;
}
/** Get a random element from the set. */
public int getRandom() {
if(len == 0)
return 0;
Random rand = new Random();
}
}