Hearts are used to play a stage. Each stage requires one heart to play, unless stated otherwise on the stage start screen.
There are two separate counters for hearts. The first one replenishes itself every 30 minutes, up to a maximum of 5. Hearts from other sources, such as from clearing Mega Pokémon stages, a log-in bonus, and Mini Hearts (Mobile only), can go over this limit. The second one does not replenish itself, and is increased by purchasing from the Shop and from StreetPass tag bonuses (3DS only).