Remove unnecessary vertices from plane mesh

I have a horizontal planar mesh that I believe could be reduced in polys (illustrative example of before and possible after below --all vertices have the same y value).

My approach so far would be to do this:

var vertices = mesh.vertices;
foreach (var vertex in vertices)
{
    if (isVertexOnEdgeOfMesh(vertex, mesh)) continue;

    var connectingVertices = GetConnectingVertices(vertex, mesh);
    var removable = true;
    foreach (var connectingVertex in connectingVertices)
    {
       if (vertex.y == connectingVertex.y) continue;

       removable = false;
       break;
    }

    if (removable)
    {
       //remove vertex here
    }
}

The idea is to remove any vertex that is not on an edge, and that also shares the same y value with all of its neighbors.

I’m not sure if this is even the right approach, but even if it is, I don’t know how to remove the vertex without screwing up the triangles in the mesh. I don’t see any reason why this type of thing shouldn’t be possible, give the layout of the mesh, but maybe I’m missing something?

I had a question similar to this and I ended up answering it my self.

heres the link:

I will maybe repost an edit with some details on how i did it, right now all I remember is that is was in some sorta backwards way.

Mainly nobody has posted on this question for two years so Im not sure if still need an answer.