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 lists 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.
See Restore contacts, calendars, and more in settings on iCloud.com in the iCloud User Guide.