125. Valid Palindrome(js)

125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

Example 1:

Input: "A man, a plan, a canal: Panama"
Output: true

Example 2:

Input: "race a car"
Output: false题意:给出一个句子,问所有单词组成的字符串是否是回文代码如下:
/**
 * @param {string} s
 * @return {boolean}
 */
var isPalindrome = function(s) {
        var len=s.length;
    var str="";
    for(var i=0;i<len;i++){
        if((s.charAt(i)>=‘a‘ && s.charAt(i)<=‘z‘) || (s.charAt(i)>=‘A‘ && s.charAt(i)<=‘Z‘)||(s.charAt(i)>=‘0‘ && s.charAt(i)<=‘9‘)){
            str+=s.charAt(i).toLowerCase();
        }
    }
    var strLen=str.length;
    for(var i=0;i<strLen;i++){
        if(str.charAt(i)!=str.charAt(strLen-1-i)){
            return false;
        }
    }
    return true;
};

原文地址:https://www.cnblogs.com/xingguozhiming/p/10864380.html

时间: 2024-07-31 10:56:33

125. Valid Palindrome(js)的相关文章

Valid Palindrome(LintCode)

Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Example "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a palindrome. Note Have you co

leetcode题解:Valid Palindrome(判断回文)

题目: 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 tha

百度静态资源(JS)公共库

     例如: chosen http://apps.bdimg.com/libs/chosen/1.1.0/chosen.jquery.min.js classlist http://apps.bdimg.com/libs/classlist/2014.01.31/classList.min.js cookies.js http://apps.bdimg.com/libs/Cookies.js/0.4.0/cookies.min.js dojo http://apps.bdimg.com/l

前台强大的图表(js)

http://www.jqplot.com/ 网址,自己下载下例子看一下就明白了. 这个是我之前做的项目中的例子(仅是部分代码): function publicMethod(){                         var plot1 = $.jqplot(chart, [currYear], {                 seriesColors: ["rgb(23, 108, 238)"],                 title: titles,     

创建HTML新元素(js)

1 <!-- 2 创建新的HTML元素 3 1.创建新的元素 4 2.创建新的节点 5 3.追加节点 6 4.向已有元素追加新的元素 7 --> 8 <html> 9 <body> 10 11 <div id="div1"> 12 <p id="p1">这是一个段落</p> 13 <p id="p2">这是另一个段落</p> 14 </div&g

每日算法之三十:Valid Sudoku (九宫格)

mnesia在频繁操作数据的过程可能会报错:** WARNING ** Mnesia is overloaded: {dump_log, write_threshold},可以看出,mnesia应该是过载了.这个警告在mnesia dump操作会发生这个问题,表类型为disc_only_copies .disc_copies都可能会发生. 如何重现这个问题,例子的场景是多个进程同时在不断地mnesia:dirty_write/2 mnesia过载分析 1.抛出警告是在mnesia 增加dump

125. Valid Palindrome【easy】

125. Valid Palindrome[easy] 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. No

leetCode 125. Valid Palindrome 字符串

125. Valid Palindrome 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:Hav

给数组添加一个根据指定下标删除元素的方法、得到0-100的随机数不重复(js)、得到外联样式的css样式值

/** *删除数组指定下标或指定对象 */ Array.prototype.remove=function(obj){ for(var i =0;i <this.length;i++){ var temp = this[i]; if(!isNaN(obj)){ temp=i; } if(temp == obj){ for(var j = i;j <this.length;j++){ this[j]=this[j+1]; } this.length = this.length-1; } } }