zoukankan      html  css  js  c++  java
  • leetcode--Palindrome Partitioning

    1.题目描述

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
     
    For example,
    "A man, a plan, a canal: Panama" is a palindrome.
    "race a car" is not a palindrome.
     
    Note:
    Have you consider that the string might be empty? This is a good question to ask during an interview.
     
    For the purpose of this problem, we define empty string as valid palindrome.

    2.解题思路

    题目很简单,但是就是要注意考虑到大小写和空字符串的问题(空字符串包括删除无用字符串之后为空的情况)

    class Solution {
    public:
        bool isPalindrome(string s) {
            // Start typing your C/C++ solution below
            // DO NOT write int main() function
            
            if(s.empty())return true;
            
            string s_argument;
            
            s_argument.push_back('#');
            
            for(int i=0;i<s.length();++i)
            {
                if((s[i]<='z'&&s[i]>='a')||(s[i]>='0'&&s[i]<='9')||(s[i]>='A'&&s[i]<='Z'))
                {
                    if(s[i]>='A'&&s[i]<='Z')
                    {
                        s_argument.push_back(s[i]-'A'+'a');
                    }
                    else s_argument.push_back(s[i]);
                    s_argument.push_back('#');
                }
            }
            
            if(s_argument.length()==1)return true;
            for(int i=s_argument.length()/2-1;i>=0;i--)
            {
                if(s_argument[i]!=s_argument[s_argument.length()-1-i])return false;
                
            }
            
            return true;    
            
        }
    };
  • 相关阅读:
    四种losses
    Yale数据库上的人脸识别
    Supervised Hashing with Kernels, KSH
    Spherical Hashing,球哈希
    YOLO(You Only Look Once)
    Iterative Quantization,ITQ
    Locality Sensitive Hashing,LSH
    循环神经网络
    Zero-shot learning(零样本学习)
    王者荣耀交流协会
  • 原文地址:https://www.cnblogs.com/obama/p/3247173.html
Copyright © 2011-2022 走看看