-
Notifications
You must be signed in to change notification settings - Fork 98
Added Happy Number #57
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
12 + 92 = 82 | ||
82 + 22 = 68 | ||
62 + 82 = 100 | ||
12 + 02 + 02 = 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.
Could you update this using a ^
? The digits together are a bit confusing.
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.
sure
strNumber = n.toString(); | ||
splitNumber = strNumber.split(""); |
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.
another solution that doesn't require translating the integer to a String would be to
get the number, apply mod 10 and divide it by 10, get the digit and repeat the process.
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.
sorry, i don't get it. could you give an example?
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.
last_digit = n % 10
n = (n - last_digit) / 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.
Thank you for contributing!
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.
Thank you!
strNumber = n.toString(); | ||
splitNumber = strNumber.split(""); |
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.
last_digit = n % 10
n = (n - last_digit) / 10
Input: s = "abc", indices = [0,1,2] | ||
Output: "abc" | ||
Explanation: After shuffling, each character remains in its position. | ||
|
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 guess this assumes the input indices is a valid input e.g. it cannot be [-1, 1023234234]
This is actually my first pull request, I start with an easy problem hehe
I hope i can contribute more
thanks,,