Case (1) ,
All the 4 digits are different in the number.
Then the digits can be arranged in 5P4=5!(5−4)!=120 ways to form the number.
Case (2)
When one digit is repeated out of 1,2,3,4,5 and other two digits used are different.
There are 5 ways to choose which digit is repeated.
There are 4C2=6 ways to choose the non repeated digits.
And 4!(2)!=12 ways to arrange all the digits.
So, with one repetition, total ways =5(6)(12)=360
Case (3)
When two digits are repeated out of 1,2,3,4,5
There are 5C2=10 ways to choose the repeated digits.
And 4!2!2!=6 ways to arrange all the digits.
So, with two repetition, total ways =10(6)=60
So, total 4-digit numbers =120+360+60=540