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. MySQL的sql_mode模式 解决数据Incorrect DECIMAL value: ‘0’ for column ” at row -1问题

    https://blog.csdn.net/weiwoyonzhe/article/details/85177294?depth_1-utm_source=distribute.pc_relevant ...

  2. Page (computer memory) Memory segmentation Page table 虚拟地址到物理地址的转换

    A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described ...

  3. poj2185Milking Grid

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8325   Accepted: 3588 Desc ...

  4. socket套接字编程(1)——基本函数

    TCP交互流程: 服务器:1. 创建socket:2. 绑定socket和端口号:3. 监听端口号:4. 接收来自客户端的连接请求:5. 从socket中读取字符:6. 关闭socket. 客户端:1 ...

  5. Golang内建库学习笔记(2)-web服务器相关

    package main import ( "net/http" "fmt" "strings" "log" ) fun ...

  6. 一条sql查出数据库某张表的所有属性

    select t.TABLE_NAME,--表名 t.COLUMN_NAME,--字段名 t.DATA_TYPE,--字段属性 t.DATA_LENGTH,--类型长度 t.DATA_PRECISIO ...

  7. 关闭Linux - centos7的防火墙

    关闭Centos7的防火墙 在每台虚拟机上分别执行以下指令: systemctl stop firewalld.service #停止firewall systemctl disable firewa ...

  8. Codeforces Global Round 9 C. Element Extermination

    题目链接:https://codeforces.com/contest/1375/problem/C 题意 给出一个大小为 $n$ 的排列 $a$,如果 $a_i < a_{i+1}$,则可以选 ...

  9. spoj687 REPEATS - Repeats (后缀数组+rmq)

    A string s is called an (k,l)-repeat if s is obtained by concatenating k>=1 times some seed strin ...

  10. SPOJ Favorite Dice(概率dp)

    题意: 一个骰子,n个面,摇到每一个面的概率都一样.问你把每一个面都摇到至少一次需要摇多少次,求摇的期望次数 题解: dp[i]:已经摇到i个面,还需要摇多少次才能摇到n个面的摇骰子的期望次数 因为我 ...