Nitrogen has half filled electronic configuration 1s22s22p3, which is a stable one and it is tough to add one electron. So its having positive electron gain enthalpy. But oxygen has 1s22s22p4 configuration and is less stable configuration compared to nitrogen. So addition of 1 electron occur and is having negative gain enthalpy.