-
Notifications
You must be signed in to change notification settings - Fork 102
Update Happy_Number.js #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi thanks for contributing.
I think it's enough to check just for 1 since 7 will eventually hit n === 1. I like the example, we can merge that 👍.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we'd need to check for 7 since it's already covered by n===1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Thanks for getting back to me, the thing is the first if condition checks whether the array's length is 1 or not,
in this case if the array has only 7 then it would be true, and since it is to return true if n===1 it would return false.
I have added some screenshots for tests please feel free to check them.
-
Not adding check for
n===7
Screenshot 2024年02月12日 at 04-33-01 Happy Number - LeetCode -
Adding checks
Screenshot 2024年02月12日 at 04-33-43 Happy Number - LeetCode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhhh true! Nice catch. We need to list all happy numbers that are less than 10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhhh true! Nice catch. We need to list all happy numbers that are less than 10.
Thank you @Alucard2169
No problem.
Added base case check for Happy number problem.
About the fix.
7Is also considered a Happy number, previously the code was checking if the array length is1andnwas1then returntrueelsefalse.