zoukankan      html  css  js  c++  java
  • 125. Valid Palindrome(LeetCode)

    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.

     1 class Solution {
     2 public:
     3     bool isPalindrome(string s) {
     4       if (s == "")
     5             return true;
     6         int len = s.size();
     7         transform(s.begin(), s.end(), s.begin(), ::tolower);
     8         string s1="";
     9         for (int i = 0; i < len; i++)
    10         {
    11             if (isalnum(s[i]))
    12             {
    13                 s1 += s[i];
    14             }
    15         }
    16         string s2 = "";
    17         s2 = s1;
    18         //transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    19         //transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
    20         reverse(s1.begin(), s1.end());
    21         cout << s2 << " " << s1 << endl;
    22         if (s2 == s1)
    23             return true;
    24         else
    25             return false;
    26     }
    27 };
  • 相关阅读:
    一些基本概念
    Linux命令
    浮点型数据
    编码习惯
    VC++ Debug编译方式
    程序和进程
    文件和目录
    登录
    c#发送http请求注意
    html5获取图片的宽高
  • 原文地址:https://www.cnblogs.com/wujufengyun/p/7192829.html
Copyright © 2011-2022 走看看