leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

palindrome-number.cpp (535B)


      1 #include <list>
      2 #include <iostream>
      3 
      4 //Leet Ratings
      5 //       Speed  Memory
      6 //Total  27ms    6.1MB    
      7 //Beats  15.5%   14.79%
      8 //
      9 
     10 
     11 using namespace std;
     12 
     13 bool isPalindrome(int x) {
     14    list<char> list1;
     15    string temp = to_string(x);
     16     for (int i = 0; i < temp.length() / 2; ++i){
     17         if(temp[i] != temp[temp.length() - i - 1]){
     18             return false;
     19         }
     20     }
     21    return true;
     22 }
     23 
     24 
     25 
     26 
     27 int main(){
     28 
     29 
     30     int input;
     31     cout << "Enter a number: ";
     32     cin >> input;
     33     cout << boolalpha <<  isPalindrome(input) << endl;
     34 
     35 
     36 }