Campaigns and outside groups are spending tens of millions of dollars on legal challenges leading up to the election, trying to avoid even more damaging — and expensive — fights after polls close.