If you accidentally deleted iCloud contacts from Contacts on Mac
If you accidentally deleted iCloud contacts, you can use iCloud.com to restore them from an earlier version that was automatically archived in iCloud. The restored contacts and contact groups appear on all your devices set up for iCloud Contacts. When you restore an earlier version, your current version is first archived in iCloud so you can change your mind and go back to it.
For instructions, see Restore contacts, calendars, and more in Settings on iCloud.com in iCloud Help.