They do not share the exact same melody. "My Country, 'Tis of Thee" (America) uses the British tune "God Save the King," which is also the basis for "God Save the Queen" (same melody, different lyrics for monarch's gender). However, the two American/British melodies are not identical—there are subtle rhythmic and ornamental differences. It's actually "God Save the Queen" and "God Bless America" that share a melodic lineage (both derived from the same British source).