a. Say delete 3 from 1 3 5 7 9, we replace 3 with 9 and erase 9, resulting in 1 9 5 7
But in the Leetcode problem Insert 380 381 Delete GetRandom O(1), when the index of the removed element, 1 in example 1, and 4 in example 2 is going to be used again in the future. Index 4 is actually out of bound in the second example.
In this case, operation sequence matters, it is infact two different types of operation sequence, while the result coincidents in some cases.
No comments:
Post a Comment