Thursday, August 11, 2016

[LeetCode] Programming Bug Note

1. Delete Element In Unordered ArrayList, Vectors

    a. Say delete 3 from 1 3 5 7 9, we replace 3 with 9 and erase 9, resulting in 1 9 5 7 9

    b. But when deleting element 9, when we replace 9 with 9, then delete 9, (Seems works ok)

        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