From this summary of how Bilbo found the Ring in The Hobbit, how did Bilbo beat Gollum at the Riddle game?

As told in The Hobbit, Bilbo found the Ring while lost in the tunnels near Gollum's lair. In the first edition, Gollum offers to surrender the Ring to Bilbo as a reward for winning the Riddle Game. When Tolkien was writing The Lord of the Rings, he realized that the Ring's grip on Gollum would never permit him to give it up willingly. He therefore revised The Hobbit: in the second edition, after losing the Riddle Game to Bilbo, Gollum went to get his "Precious" to help him kill and eat Bilbo, but found the Ring missing.[1] Deducing from Bilbo's last question—"What have I got in my pocket?"—that Bilbo had found the Ring, Gollum chased him through the caves, not realizing that Bilbo had discovered the Ring's power of invisibility and was following him to the cave's mouth. Bilbo escaped Gollum and the goblins by remaining invisible, but he chose not to tell Gandalf and the dwarves that the Ring had made him invisible. Instead he told them a story that followed the first edition: that Gollum had given him the Ring and shown him the way out. Gandalf was immediately suspicious of the Ring, and later forced the real story from Bilbo.

Gollum was unable to answer Bilbo's last question, "What have I got in my pocket?".