I would like to know whether these two expressions are both correct and have the same meaning. I've been searching on google and on online dictionaries and I didn't find any answer to that question.
(You can answer in French if you prefer.)
French Language Stack Exchange is a question and answer site for students, teachers, and linguists wanting to discuss the finer points of the French language. It only takes a minute to sign up.Sign up to join this community
Both are correct but penser and penser à have different meanings in your examples, even if it is only a slight one.
J'ai pensé la même chose.
Penser is followed by a direct object. The stress lies in the result of the thought process: you are stressing the fact that your idea is the same as that of the person you are talking to.
J'ai pensé à la même chose.
Penser à is followed by an indirect object. The stress here is on the action: the important thing is that you have been engaged in reflection.
You have the same difference in meaning in English between "think" and "think about".
You might be interested in this other answer about penser.