Maine and Nebraska choose electors by congressional district. Because the two states in modern times have had only five districts between them, a candidate losing one of the states but winning in one of the districts and gaining an elector is rare. This never happened in the 20th century, though it often happened in the 19th century when choosing electors by congressional districts was more common.
In the 21st century it happened twice, Obama winning a district and an EV in Nebraska in 2008, and Trump winning a district and an EV in Maine in 2016 (the only time so far in this century the Republicans have gotten an New England EV or the Democrats a Plains state EV). Perot came very close in carrying an identical version of that Maine congressional district, so you could get him an EV without changing much at all about the campaign.