• + 1 comment

    Maybe it's been said before, but to simplify you can just have this in the loop:

    if (!colors.add(c[i]) { colors.remove(c[i]); pairs++; }

    soz for no code markdown idk how