Let’s say you read books in the library to develop your writing skills, and then write your own medieval fantasy book. Even if you include magical rings, elves and dwarves, I don’t think anyone will sue you just because your story is clearly inspired by a specific book. The key is to avoid making s word for word copy.