Both can be plausible answers. One is a common psychological response to adversity and/or a simple social construct [brids of a feather flock together] that allows for like-minded people to band together.
On the other hand, the saying 'opposites attract' may apply to people who may be drawn into certain individuals because of traits that they lack firsthand. If someone is inquisitive and humorous while the other is serious and tactile, they could form a productive educational group or mold a fitting romantic relationship.