Let's say I have a list [1, 2, 3, 4, 2, 5]
. Since 2
occurs twice, I want to remove the last occurrence of two. This is what I have done so far.
list.reverse()
list.remove(value) # value = 2
list.reverse()
But it seems that if I'm doing reversing twice for deleting a value, the algorithm complexity would be O(n)
. Is there any faster way of doing it?