Republican Donald Trump has won Pennsylvania, Georgia and North Carolina, capturing three of the seven heavily contested battlegrounds and coming within a few electoral votes of winning the presidency.