First you would have to find vertexes that are on top of each other. This is at least O(n log n) complexity, increasing in cost as the number of vertexes rises. Then for each match you would delete one vertex, then find all the triangles that reference the second vertex and change that reference to the first vertex.
Of course, none of this would preserve the texture or colour values for the vertex, so the mesh couldn't reliably have textures or colours in it.