$y'+y=\begin{cases}2&0<t<1,\\0&t>1.\end{cases}=2{\bf H}_0(t)-2{\bf H}_1(t)$ with $y(0)=0$ using Laplace method
$$s{\cal L}(y)+{\cal L}(y)=2\dfrac{1-e^{-s}}{s}$$
then
$${\cal L}(y)=2\left(\dfrac{1}{s}-\dfrac{e^{-s}}{s}-\dfrac{1}{s+1}+\dfrac{e^{-s}}{s+1}\right)$$
and
$$y(t)=2\begin{cases}1-e^{-t}&0<t<1,\\e^{-t+1}-e^{-t}&t>1.\end{cases}$$
where ${\bf H}$ is Heaviside step function.
0
user65203
On
Hint:
$$(y'(t)+y(t))e^t=(y(t)e^t)'=g(t)e^t$$ so that
$$y(t)e^t-y(0)=\int_0^t g(t)e^tdt.$$
The rest is yours.
Related Questions in ORDINARY-DIFFERENTIAL-EQUATIONS
$y'+y=\begin{cases}2&0<t<1,\\0&t>1.\end{cases}=2{\bf H}_0(t)-2{\bf H}_1(t)$ with $y(0)=0$ using Laplace method $$s{\cal L}(y)+{\cal L}(y)=2\dfrac{1-e^{-s}}{s}$$ then $${\cal L}(y)=2\left(\dfrac{1}{s}-\dfrac{e^{-s}}{s}-\dfrac{1}{s+1}+\dfrac{e^{-s}}{s+1}\right)$$ and $$y(t)=2\begin{cases}1-e^{-t}&0<t<1,\\e^{-t+1}-e^{-t}&t>1.\end{cases}$$ where ${\bf H}$ is Heaviside step function.