Technically that's fine. Copyright only protects originality, not novelty as with patents. Coincidentally creating the same melody as someone else doesn't violate their copyright. If they sued they'd have to prove that it wasn't coincidental with evidence that you heard the original melody, a prerequisite for proving that your melody was derivative.
That's the theory. In practice the first person to publish the melody often wins, especially if their version was popular--e.g. a radio hit, which by itself provides circumstantial evidence that you had heard it.
This also completely ignores there is not a finite number of notes - ever heard someone play a theremin? - and even you restrict yourself to finite tuning systems, there are many to choose from. These can also be used in a pop context - if extremely rarely.