C++ solution with string, beats 100%, just 5 lines


  • -1
    C
    class Solution {
    public:
        bool isPalindrome(int x) {
            string s = std::to_string(x);
    	for (int i = 0; i < s.size() / 2; i++)
    		if (s[i] != s[s.size() - i - 1])
    			return false;
    	return true;
        }
    };
    

  • 0
    A

    you cannot use extra space


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.