GFG Dsa
GFG Dsa
Given a number N, the task is to return the count of digits in this number.
Example:
class GFG {
/* Driver code */
public static void main(String[] args)
{
long n = 345289467;
System.out.print("Number of digits : "
+ countDigit(n));
}
}
Output
Number of digits : 9
Time Complexity : O(log10(n)) or θ(num digits)
Auxiliary Space: O(1) or constant
Palindrome Numbers
Given an integer, write a function that returns true if the given number is palindrome, else false. For
example, 12321 is palindrome, but 1451 is not palindrome.
A simple approach to check if a number is Palindrome or not . This approach can be used when the
number of digits in the given number is less than 10^18 because if the number of digits of that number
exceeds 10^18, we can’t take that number as an integer since the range of long long int doesn’t satisfy
the given number.
To check whether the given number is palindrome or not we will just reverse the digits of the given
number and check if the reverse of that number is equal to the original number or not . If reverse of
number is equal to that number than the number will be Palindrome else it will not a Palindrome.
C++JavaPython3C#Javascript
/*package whatever //do not write package name here */
import java.io.*;
class GFG {
// Java program to check if a number is Palindrome
// Driver Code
public static void main(String args[])
{
int n = 7007;
if (checkPalindrome(n) == true) {
System.out.println("Yes");
}
else {
System.out.println("No");
}
}
}
Output
Yes
Time Complexity : O(log(n)) or O(Number of digits in a given number)
Auxiliary space : O(1) or constant