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 ...
随机推荐
- 通过 profiling 定位 golang 性能问题 - 内存篇 原创 张威虎 滴滴技术 2019-08-02
通过 profiling 定位 golang 性能问题 - 内存篇 原创 张威虎 滴滴技术 2019-08-02
- 一套高可用、易伸缩、高并发的IM群聊、单聊架构方案设计实践
一套高可用.易伸缩.高并发的IM群聊.单聊架构方案设计实践 一套高可用.易伸缩.高并发的IM群聊.单聊架构方案设计实践-IM开发/专项技术区 - 即时通讯开发者社区! http://www.52im. ...
- https://dev.mysql.com/doc/refman/8.0/en/savepoint.html
https://dev.mysql.com/doc/refman/8.0/en/savepoint.html
- pickle — Python object serialization
pickle - Python object serialization 消息队列
- 思考gRPC :为什么是HTTP/2
Introducing gRPC Support with NGINX 1.13.10 - NGINX https://www.nginx.com/blog/nginx-1-13-10-grpc/ 思 ...
- TypeScript基本类型
类型注解 作用:相当于强类型语言中的类型声明 语法:(变量/函数):type 数据类型 新建src/datatype.ts,里面定义各种类型的数据 原始类型: let bool: boolean = ...
- 在 ASP.NET Core 应用中使用 Cookie 进行身份认证
Overview 身份认证是网站最基本的功能,最近因为业务部门的一个需求,需要对一个已经存在很久的小工具网站进行改造,因为在逐步的将一些离散的系统迁移至 .NET Core,所以趁这个机会将这个老的 ...
- docker基本使用-常用命令
一. 常用命令 #查看docker服务 docker ps #启动docker服务 systemctl start docker #查看本地镜像 docker images #删除本地镜像 docke ...
- JYM虚拟机性能监控与故障处理工具
虚拟机性能监控与故障处理工具 一.jps:虚拟机进程状况工具 常用指令 二.jstat:虚拟机统计信息监视工具 常用指令 三.jinfo:配置信息工具 四.jmap:Java内存映像工具 常用指令 五 ...
- toggle() 隐藏和收缩
<!DOCTYPE html><html><head><script src="/jquery/jquery-1.11.1.min.js" ...