Code:
// pseudo code
vertices = set()
foreach triangle:
    foreach vertex of triangle:
        vertices.add(vertex.x, vertex.y, vertex.z, vertex.nx, vertex.ny, vertex.nz, vertex.u, vertex.v)



The set or map or some other hashed data structure will make sure that you will end up with exactly the amount of vertices you need for your vertex buffer. Afterwards you can loop through the triangles again to build your index buffer.