In most circumstances, the short response is yes. Most of the time, dangerous files or programs on your phone contain viruses. A factory reset usually removes the problematic virus or malware because it deletes all your files.