Ref. No. 1169/42-421
In the name of Allah the most Gracious the most Merciful
The answer to your question is as follows:
Being ever mindful of Allah and fearing the punishment of Resurrection Day will help you get rid of engaging in something that is hated by Allah. You can try fasting on a regular basis to help reduce your desire. The real solution is only to get married as early as possible.
You should avoid solitude and repeatedly make dua and ask Allah (swt) to make it easy for you to refrain from this addictive evil. Moreover, you can take pledge for yourself to keep some fasts or to pay sadaqa in case you fall in this sin. This will be much useful for you. May Allah help you! Ameen
And Allah knows best
Darul Ifta
Darul Uloom Waqf Deoband