[LeetCode 125,136][简单]验证回文串/只出现一次的数字

125.验证回文串
题目链接

class Solution {
public:
    bool isv(char p){
        if(p<='z' && p>='a')return true;
        if(p<='9' && p>='0')return true;
        return false;
    }
    bool isPalindrome(string s) {
        int i = 0,j = s.size()-1;
        std::transform(s.begin(),s.end(),s.begin(),::tolower);
        while(i<=j){
            while(i<j && !isv(s[i])) i++;
            while(i<j && !isv(s[j])) j--;
            if(s[i++]!=s[j--])return false;
        }
        return true;
    }
};

136.只出现一次的数字
题目链接

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        ios::sync_with_stdio(false);
        int ans = 0;
        for(auto i : nums){
            ans^=i;
        }
        return ans;
    }
};
发布了104 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/IDrandom/article/details/104176415