Let x be the distance traveled by train A and Let y be the distance traveled by Train B before they meet.
When they meet,
x+y = 62 km
I know Distance = speed X time
Let t be the time when they meet.
x = 18t
y = 22t
Substituting x and y in above equation,
18t + 22t = 62
40t = 62
t = 62/40 hr