While I'm a huge advocate for public transportation since it is usually the cheapest option for getting around when traveling — besides walking, of course! — if you want to avoid the crowds when visiting Versailles, taking an Uber is the way to go.
Since there have been so many train strikes in and around Paris, taking an Uber will be a much more reliable source to ensure you arrive to the palace at your desired time. Not to mention, the walk to Versailles from the train station takes a good 20 minutes, whereas an Uber will bring you right up to the gates.
I recommend spending the extra money, and then saving on costs by taking the train back to Paris, or your original destination. Be mindful that the drive to Versailles from Paris takes around 45 minutes, so make sure to add that time in your itinerary when making your plans.