People who suggest a "lack of magnesium" or a "lack of potassium" should educate themselves - it's neither. It's a lack of salt.
I'm not blaming them since their beliefs are based on what the medical profession claims and you can't know what you haven't learned. But aside from the medical professions misinformation department, a simple exercise in common sense should provide some indicators. To wit:
The body is composed of around 75% water. This is because everything is tied to water and water regulates every function.
The body gets all of the nutrients it needs to function from food (except adequate amounts of water - you have to actually drink water). Naturally, excessive amounts of most vitamins and minerals are consumed every day, and when this happens, the body uses what it needs and discards the rest. This is something the medical profession doesn't give the body enough credit for - being able to take care of itself.
While we do get too much salt from processed foods, this excess salt is discarded the same as any other nutrient consumed in excess - unless it's needed for a reason (such as to retain water when you don't drink enough. This is the "excess salt" that doctors incorrectly blame for high blood pressure).
Through its normal function, the body loses around 2 quarts of water per day - and with this water goes salt. Thus, you're losing salt at a much faster rate than you're losing other nutrients. When you replace the water you lose, you also need to replace the salt.
But most people don't replace the water adequately, and thus, the chances of replacing the salt are much worse thanks to the way the medical profession demonizes salt.
Therefore, it isn't a lack of magnesium or a lack of potassium that causes leg cramps - you get plenty of those nutrients. It's a lack of salt - and water.