U.S. inflation accelerated last month as gasoline and many other goods and services became more expensive just a few weeks before midterm elections.