My professor gave me the integral $$\lambda = \int (1+2x^2)e^{x^2}dx$$ and I solved through substituition $y=x^2$ and then by parts $u=\sqrt{y}$, $dv=e^y dy$. $$ \lambda = \int e^y(1+2y) \frac{dy}{2 \sqrt y} = \int \frac{e^y}{2y^{1/2}}dy + \int e^y y^{1/2} dy $$ And $$ \int \frac{e^y}{2y^{1/2}}dy = e^y y^{1/2} - \int e^y y^{1/2}dy $$
Thus $\lambda = e^yy^{1/2}+C=xe^{x^2}+C$.
He said that there's a trick that solves in one line, and told me that is a trick in the same sense of the one used in $$\int \cos(x)e^xdx$$
Can someone see this trick? Or maybe there isn't one and he got confused.
So, if you differentiate $e^{x^2}$ twice (as one would be inclined to do on trying integration by parts, where you have to differentiate the exponential - and is how I found it), you get
$$\newcommand{\dd}{\mathrm{d}} \newcommand{\dv}[2]{\frac{\dd #1}{\dd #2}} \dv{^2}{x^2} e^{x^2} = 2 \cdot \color{blue}{e^{x^2} (1+2x^2)}$$
Hence,
$$\lambda = \frac 1 2 \int \dv{^2}{x^2} e^{x^2} \, \dd x=C+\frac 1 2 \dv{}{x} e^{x^2}=C+\frac 1 2 \cdot 2xe^{x^2}=xe^{x^2}+C$$
Note that this is actually the answer since, after all, your answer on differentiation gives
$$\dv{}{x} \Big( xe^x + C \Big) = (x+1) e^x \ne e^{x^2} (1+2x^2)$$
If you make the substitution $y := x^2$ and hence $\dd y = 2x \, \dd x$ in the original integral, you get
$$\lambda = \int e^y(1+2y) \frac{\dd y}{2 \sqrt y}=\frac 1 2 \int e^y \Big( y^{-1/2} + 2y^{1/2} \Big) \, \dd y$$
so I'm not sure how your claimed integration by parts would apply here.