The confusion is actually caused by your “remove” function. In java, there are two remove functions.
-
remove() -> This is to remove the head/root, it takes O(logN) time.
-
remove(Object o) -> This is to remove an arbitrary object. Finding this object takes O(N) time, and removing it takes O(logN) time.