int型转string型(不断拓展中)

int型转string型

最近做leetcode题,做到第9. Palindrome Number,我的解决方法为int转换为string,此为类型转换的一种方法,mark一下。

class Solution {
public:
    bool isPalindrome(int x) {
    if(x<0)
        return false;
    if(x==0)
        return true;
    stringstream ss;
    string str;
    ss<>str;
    int i=0,j=str.size()-1;
    while(i<=j){
        if(str[i]!=str[j])
            return false;
        i++;
        j--;
    }
    return true;
    }
};

你可能感兴趣的:(c++小问题汇总,string,leetcode,int)