An automorphic number is a number whose square ends with the number itself. For example, 5 is automorphic because 5 squared is 25, which ends with 5. Similarly, 76 is automorphic because 76 squared is 5776, which ends with 76. Given an integer, determine if it is an automorphic number. Return false for null or negative input.
Examples:
Input: num = 5
Output: true
Explanation: 5 * 5 = 25, which ends with 5
Input: num = 76
Output: true
Explanation: 76 * 76 = 5776, which ends with 76
Input: num = 7
Output: false
Explanation: 7 * 7 = 49, which does not end with 7
Input: num = 0
Output: true
Explanation: 0 * 0 = 0, which ends with 0
Input: num = null
Output: false
Explanation: Null input returns false
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 All Time Leaderboard
Contest runs January 1, 1970 - December 31, 9999. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.