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!

How 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

Note

You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In