![]() |
VOOZH | about |
Given a number s in the form of string, the task is to check if the number is divisible by 5.
Examples:
Input : s = 56945255
Output : trueInput : s = 12345
Output : trueInput : s = 36358839596
Output : false
Table of Content
Convert the given string to an integer by iterating through each digit, then check if it's divisible by 5 using modulo operator. This approach might cause overflow for very large numbers.
1
A number is divisible by 5 if and only if its last digit is 0 or 5. Since the number can be very large (given as string), directly check the last character instead of converting to integer.
1