In the biography - Einstein - His Life and Universe, by Walter Isaacson, the author says that Einstein never failed in mathematics in school - it is a common misconception.
Einstein himself said "I never failed in mathematics. Before I was fifteen, I had mastered differential and integral calculus." In fact he was very often ranked first in his class.
Einstein's view was influenced by his uncle Jacob Einstein, who said "It is a merry science. When the animal that we are hunting cannot be caught, we call it "X" temporarily, and continue to hunt it until it is bagged."