forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_palindrome.dart
56 lines (38 loc) · 1014 Bytes
/
check_palindrome.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Dart program to check if a number is a palindrome or not
* A palindromic number is a number that remains the same when its digits are reversed.
*/
import 'dart:io';
int isPallindrome(int num) {
int temp = num;
int rev = 0;
/*First reverse the number and then compare it with the given number to check pallindrome*/
while (temp != 0) {
int rem = temp % 10;
rev = rev * 10 + rem;
temp = (temp / 10).floor();
}
if (rev == num) {
print("The given number is a palindrome number");
} else {
print("The given number is not a palindrome number");
}
return 0;
}
int main() {
stdout.write("Enter the number: ");
int num = int.parse(stdin.readLineSync()!);
isPallindrome(num);
return 0;
}
/*
Time Complexity: O(log(n)), where 'n' is the given number
Space Complexity: O(1)
SAMPLE INPUT AND OUTPUT
SAMPLE 1
Enter the number: 24324
The given number is not a palindrome number
SAMPLE 2
Enter the number: 73137
The given number is a palindrome number
*/