0
点赞
收藏
分享

微信扫一扫

算法题2:回文数

 

    if(x<0){
		return false
	}else{
		x = x.toString()
		const chars = [ ...x ]
		if(chars.length == 1){
			return true
		}
		if(chars.length % 2 == 0){
			for(var i = 0; i <= chars.length/2; i++){
				if(chars[i] == chars[chars.length-1-i]){
					
				}else{
					return false
				}
			}
			return true
		}
		if(chars.length % 2 != 0){
			for(var i = 0; i <= chars.length/2; i++){
				if(chars[i] == chars[chars.length-1-i]){
					
				}else{
					return false
				}
			}
			return true
		}
	}

举报

相关推荐

0 条评论