leetcode

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

palindrome-numberV2.cpp (699B)


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