leetcode bug & 9. Palindrome Number

bug

shit bug

  1. "use strict";
  2. /**
  3. *
  4. * @author xgqfrms
  5. * @license MIT
  6. * @copyright xgqfrms
  7. * @created 2020-07-23
  8. * @modified
  9. *
  10. * @description 9. Palindrome Number
  11. * @difficulty Easy
  12. * @complexity O(n)
  13. * @augments
  14. * @example
  15. * @link https://leetcode.com/problems/palindrome-number/
  16. * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10
  17. * @solutions
  18. *
  19. */
  20. const log = console.log;
  21. /**
  22. * @param {number} x
  23. * @return {boolean}
  24. */
  25. var isPalindrome = function(num) {
  26. if(num < 0) {
  27. return false;
  28. } else {
  29. const len = Math.ceil(Math.log10(num + 1));
  30. if (len <= 1) {
  31. return true;
  32. } else {
  33. const temp = DigitsArrayToNumber(NumberToDigitsArray(num));
  34. if(num === temp) {
  35. return true;
  36. } else {
  37. return false;
  38. }
  39. }
  40. }
  41. };
  42. function DigitsArrayToNumber(arr) {
  43. let result = 0;
  44. let len = arr.length;
  45. if(len > 2) {
  46. while (len > 0) {
  47. result += arr[len - 1] * Math.pow(10, len - 1);
  48. len--;
  49. }
  50. } else {
  51. result = arr[0]*10 +arr[1];
  52. }
  53. return result;
  54. }
  55. function NumberToDigitsArray(num) {
  56. const result = [];
  57. while (num > 0) {
  58. result.push(num % 10);
  59. num = parseInt(num / 10);
  60. }
  61. return result;
  62. }
  63. const test = isPalindrome(123);
  64. const test1 = isPalindrome(-123);
  65. const test2 = isPalindrome(10);
  66. const test3 = isPalindrome(11);
  67. log(`test`, test)
  68. log(`test1`, test1)
  69. log(`test2`, test2)
  70. 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. 通过 profiling 定位 golang 性能问题 - 内存篇 原创 张威虎 滴滴技术 2019-08-02

    通过 profiling 定位 golang 性能问题 - 内存篇 原创 张威虎 滴滴技术 2019-08-02

  2. 一套高可用、易伸缩、高并发的IM群聊、单聊架构方案设计实践

    一套高可用.易伸缩.高并发的IM群聊.单聊架构方案设计实践 一套高可用.易伸缩.高并发的IM群聊.单聊架构方案设计实践-IM开发/专项技术区 - 即时通讯开发者社区! http://www.52im. ...

  3. https://dev.mysql.com/doc/refman/8.0/en/savepoint.html

    https://dev.mysql.com/doc/refman/8.0/en/savepoint.html

  4. pickle — Python object serialization

    pickle - Python object serialization  消息队列

  5. 思考gRPC :为什么是HTTP/2

    Introducing gRPC Support with NGINX 1.13.10 - NGINX https://www.nginx.com/blog/nginx-1-13-10-grpc/ 思 ...

  6. TypeScript基本类型

    类型注解 作用:相当于强类型语言中的类型声明 语法:(变量/函数):type 数据类型 新建src/datatype.ts,里面定义各种类型的数据 原始类型: let bool: boolean = ...

  7. 在 ASP.NET Core 应用中使用 Cookie 进行身份认证

    Overview 身份认证是网站最基本的功能,最近因为业务部门的一个需求,需要对一个已经存在很久的小工具网站进行改造,因为在逐步的将一些离散的系统迁移至 .NET Core,所以趁这个机会将这个老的 ...

  8. docker基本使用-常用命令

    一. 常用命令 #查看docker服务 docker ps #启动docker服务 systemctl start docker #查看本地镜像 docker images #删除本地镜像 docke ...

  9. JYM虚拟机性能监控与故障处理工具

    虚拟机性能监控与故障处理工具 一.jps:虚拟机进程状况工具 常用指令 二.jstat:虚拟机统计信息监视工具 常用指令 三.jinfo:配置信息工具 四.jmap:Java内存映像工具 常用指令 五 ...

  10. toggle() 隐藏和收缩

    <!DOCTYPE html><html><head><script src="/jquery/jquery-1.11.1.min.js" ...