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.)
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.
J'ai pensé la même chose que toi.
J'ai pensé à ma vie.
The first phrase is about an idea - the second is about an object that is not a thought! You can also say "J'ai pensé que ma vie était nulle" but you cannot say "J'ai pensé ma vie était nulle" .