leetcode bug & 9. Palindrome Number

bug

shit bug

"use strict";

/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-07-23
* @modified
*
* @description 9. Palindrome Number
* @difficulty Easy
* @complexity O(n)
* @augments
* @example
* @link https://leetcode.com/problems/palindrome-number/
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10
* @solutions
*
*/ const log = console.log; /**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function(num) {
if(num < 0) {
return false;
} else {
const len = Math.ceil(Math.log10(num + 1));
if (len <= 1) {
return true;
} else {
const temp = DigitsArrayToNumber(NumberToDigitsArray(num));
if(num === temp) {
return true;
} else {
return false;
}
}
}
}; function DigitsArrayToNumber(arr) {
let result = 0;
let len = arr.length;
if(len > 2) {
while (len > 0) {
result += arr[len - 1] * Math.pow(10, len - 1);
len--;
}
} else {
result = arr[0]*10 +arr[1];
}
return result;
} function NumberToDigitsArray(num) {
const result = [];
while (num > 0) {
result.push(num % 10);
num = parseInt(num / 10);
}
return result;
} const test = isPalindrome(123);
const test1 = isPalindrome(-123);
const test2 = isPalindrome(10);
const test3 = isPalindrome(11); log(`test`, test)
log(`test1`, test1)
log(`test2`, test2)
log(`test3`, test3)

refs

https://leetcode.com/problems/palindrome-number/

https://repl.it/@xgqfrms/leetcode-9-Palindrome-Number

https://leetcode.com/problems/palindrome-number/discuss/752073/9.-Palindrome-Number



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


leetcode bug & 9. Palindrome Number的更多相关文章

  1. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  2. leetcode 第九题 Palindrome Number(java)

    Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...

  3. leetcode题解 9. Palindrome Number

    9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...

  4. 【LeetCode】9. Palindrome Number (2 solutions)

    Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...

  5. C# 写 LeetCode easy #9 Palindrome Number

    9.Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it ...

  6. [LeetCode 题解]:Palindrome Number

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Determine ...

  7. LeetCode(9) - Palindrome Number

    题目要求判断一个整数是不是回文数,假设输入是1234321,就返回true,输入的是123421,就返回false.题目要求in-place,思路其实很简单,在LeetCode(7)里面我们刚好做了r ...

  8. 【一天一道LeetCode】#9. Palindrome Number

    一天一道LeetCode系列 (一)题目 Determine whether an integer is a palindrome. Do this without extra space. Some ...

  9. LeetCode Problem 9:Palindrome Number回文数

    描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

随机推荐

  1. 跨度实际上是用来计算排位(rank) 目标节点在跳跃表中的排位 有序集 排序计算

    跳跃表的实现 - Redis 设计与实现 http://redisbook.com/preview/skiplist/datastruct.html 有序集合 /* ZSETs use a speci ...

  2. SumatraPDF设置护眼背景

    高级选项中: 1 FixedPageUI [ 2 TextColor = #000000 3 BackgroundColor = #C7EDCC 4 SelectionColor = #f5fc0c ...

  3. python3编码转换

    str->bytes:encode编码 bytes->str:decode解码 字符串通过编码成为字节码,字节码通过解码成为字符串. >>> text = '我是文本' ...

  4. odoo-nginx 配置

    p.p1 { margin: 0; font: 12px "Andale Mono"; color: rgba(40, 254, 20, 1); background-color: ...

  5. 硬核!八张图搞懂 Flink 端到端精准一次处理语义 Exactly-once(深入原理,建议收藏)

    Flink 在 Flink 中需要端到端精准一次处理的位置有三个: Source 端:数据从上一阶段进入到 Flink 时,需要保证消息精准一次消费. Flink 内部端:这个我们已经了解,利用 Ch ...

  6. SpringMVC请求参数的获取方式

    一.GET请求参数获取 1. 通过HttpServletRequest获取参数 2. 直接方法参数获取 3. RequestParam注解方式获取请求参数 4. Bean方式获取参数 5. Model ...

  7. 使用Docker Registry管理Docker镜像

    文章目录 使用Docker Registry管理Docker镜像 1.使用Docker Hub管理镜像 1.1注册与登录 1.2创建仓库 1.3推送镜像 2. 使用私有仓库管理镜像 2.1 搭建私有仓 ...

  8. debian 屌丝日记

    好几年前,刚开始学习linux时,写的笔记,现在看来还挺有意思的,发出来 纪念下   1.安装debian系统,只安装最基本系统 不要桌面,不要print server,具体不会看网上图文并茂的 1) ...

  9. netty写Echo Server & Client完整步骤教程(图文)

    1.创建Maven工程 1.1 父节点的pom.xml代码(root pom文件) 1 <?xml version="1.0" encoding="UTF-8&qu ...

  10. 2019 第十届蓝桥杯大赛软件类省赛 Java A组 题解

    2019 第十届蓝桥杯大赛软件类省赛 Java A组 试题A 题解 ​ 题目最后一句贴心的提示选手应该使用 long (C/C++ 应该使用 long long). ​ 本题思路很直白,两重循环.外层 ...