The short answer
No. There is no substantive evidence that Einstein wrote or spoke this sentence. It is listed in the "Misattributed to Einstein" section of The Ultimate Quotable Einstein, the reference compilation published by Princeton University Press. Einstein died in 1955; the earliest known matches of this phrasing appear in the early 1980s.
Where the line actually comes from
The researcher Garson O'Toole, who runs Quote Investigator, traces the earliest strong match to an October 1981 newspaper article in Knoxville, Tennessee describing an Al-Anon meeting. A close variant appeared the following month, in a November 1981 Narcotics Anonymous text, phrased as insanity being the repetition of the same mistakes while expecting different results. In 1983 the novelist Rita Mae Brown put a version in her novel Sudden Death, spoken by a character named Jane Fulton — which is the citation The Ultimate Quotable Einstein points to.
So the real origin is recovery literature, not physics
That is the striking part. A saying that emerged from addiction-recovery culture — where it described the lived experience of relapse — was gradually detached from that context and handed to a theoretical physicist who had been dead for a quarter of a century. The idea also has older ancestors: O'Toole notes that linking insanity to fruitless repetition goes back well into the nineteenth century.
Why Einstein, specifically
Misattribution follows fame, and it follows it in a predictable direction. A line about flawed reasoning wants a genius; a line about peace wants Gandhi; a line about liberty wants Voltaire. Einstein is the largest magnet in English for anything that sounds cleverly scientific — the same quote has also been pinned on Benjamin Franklin and Mark Twain, neither of whom said it either.
Is the idea itself wrong?
Not at all, and this is worth holding onto. The counsel is sound: if a method keeps producing the same disappointing result, the method is what should change. What is wrong is the citation, not the advice. As an anonymous saying it loses none of its force — while gaining the advantage of being true.
What this means for your English
This quote is a small lesson in how English speakers borrow authority. Notice the move: "As Einstein said…" substitutes a famous name for an argument. Learning to say instead "there's a saying that…" makes you sound both more natural and more careful than most native speakers manage.