leetcode bug & 9. Palindrome Number
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的更多相关文章
- 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...
- leetcode 第九题 Palindrome Number(java)
Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...
- leetcode题解 9. Palindrome Number
9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...
- 【LeetCode】9. Palindrome Number (2 solutions)
Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...
- C# 写 LeetCode easy #9 Palindrome Number
9.Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it ...
- [LeetCode 题解]:Palindrome Number
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Determine ...
- LeetCode(9) - Palindrome Number
题目要求判断一个整数是不是回文数,假设输入是1234321,就返回true,输入的是123421,就返回false.题目要求in-place,思路其实很简单,在LeetCode(7)里面我们刚好做了r ...
- 【一天一道LeetCode】#9. Palindrome Number
一天一道LeetCode系列 (一)题目 Determine whether an integer is a palindrome. Do this without extra space. Some ...
- LeetCode Problem 9:Palindrome Number回文数
描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
随机推荐
- 关于BI测试
BI测试: BI是从数据接入.数据准备.数据分析.数据可视化到数bai据分发应用的一系列过程,目的是为了辅助企业高效决策.而报表虽然最终也实现了数据可视化,但是对于数据分析的维度.深度.颗粒度.实时性 ...
- 用tqdm和rich为固定路径和目标的python算法代码实现进度条
适用场景 在存在固定长度的算法中可以可视化算法执行的过程,比如对一个固定长度的数组的遍历,就是一种适合使用进度条来进行可视化的场景.而一些条件循环,比如while循环,不一定适合使用进度条来对算法执行 ...
- 题解 P1248 【加工生产调度】
题目 某工厂收到了 n 个产品的订单,这 n 个产品分别在 A.B 两个车间加工,并且必须先在 A 车间加工后才可以到 B 车间加工. 某个产品 i 在 A.B 两车间加工的时间分别为 Ai,Bi 怎 ...
- loj10153二叉苹果树
有一棵二叉苹果树,如果数字有分叉,一定是分两叉,即没有只有一个儿子的节点.这棵树共 N 个节点,标号 1 至 N,树根编号一定为 1. 我们用一根树枝两端连接的节点编号描述一根树枝的位置.一棵有四根树 ...
- Spring Boot中进行Junit测试
Spring Boot新版本默认使用Junit5,pom依赖为: <dependency> <groupId>org.springframework.boot</grou ...
- java实现注销登录
servlet HttpServletRequest request HttpSession session=request.getSession(); session.removeAttribute ...
- ESRI,空间数据处理,WKT,GeoJson
ESRI,空间数据处理,WKT,GeoJson 一.WKT 二.GeoJson 三.WKT转GeoJson 四.GeoJson 转 WKT 一.WKT WKT(well-known text)是一种文 ...
- Maven多模块的2种依赖管理策略
在Maven多模块的时候,管理依赖关系是非常重要的,各种依赖包冲突,查询问题起来非常复杂,于是就用到了<dependencyManagement>, 示例说明, 在父模块中: <de ...
- UDP发送文件
接收端 package com.zy.demo2; import java.io.File; import java.io.FileOutputStream; import java.net.Data ...
- Codeforces Round #655 (Div. 2) B. Omkar and Last Class of Math
题目链接:https://codeforces.com/contest/1372/problem/B 题意 给出一个正整数 $n$,找到两个正整数 $a,b$ 满足 $a+b = n$ 且 $LCM( ...