8.json 3.0 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
{
   "question_id": 9,
   "question_title": "回文数",
   "difficulty": "简单",
   "question_content": "<p>给你一个整数 <code>x</code> ,如果 <code>x</code> 是一个回文整数,返回 <code>true</code> ;否则,返回 <code>false</code> 。</p><p>回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,<code>121</code> 是回文,而 <code>123</code> 不是。</p><p> </p><p><strong>示例 1:</strong></p><pre><strong>输入:</strong>x = 121<strong><br />输出:</strong>true</pre><p><strong>示例 2:</strong></p><pre><strong>输入:</strong>x = -121<strong><br />输出:</strong>false<strong><br />解释:</strong>从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。</pre><p><strong>示例 3:</strong></p><pre><strong>输入:</strong>x = 10<strong><br />输出:</strong>false<strong><br />解释:</strong>从右向左读, 为 01 。因此它不是一个回文数。</pre><p><strong>示例 4:</strong></p><pre><strong>输入:</strong>x = -101<strong><br />输出:</strong>false</pre><p> </p><p><strong>提示:</strong></p><ul>\t<li><code>-2<sup>31</sup> <= x <= 2<sup>31</sup> - 1</code></li></ul><p> </p><p><strong>进阶:</strong>你能不将整数转为字符串来解决这个问题吗?</p>",
   "topic_link": "https://bbs.csdn.net/topics/600471100",
   "cpp": "bool isPalindrome(int x)\n{\n\tif (x < 0)\n\t\treturn false;\n\tchar r[11];\n\tint n = snprintf(r, 11, \"%d\", x);\n\tint i;\n\tfor (i = 0; i < n / 2; i++)\n\t{\n\t\tif (r[i] != r[n - i - 1])\n\t\t\treturn false;\n\t}\n\treturn true;\n}",
   "java": "class Solution {\n\tpublic boolean isPalindrome(int x) {\n\t\tlong r;\n\t\tlong o = x;\n\t\tlong y = 0;\n\t\twhile (x > 0) {\n\t\t\tr = x % 10;\n\t\t\ty = y * 10 + r;\n\t\t\tx = (int) Math.floor(x / 10);\n\t\t}\n\t\treturn y == o;\n\t}\n}",
   "js": "/**\n * @param {number} x\n * @return {boolean}\n */\nvar isPalindrome = function(x) {\n    let r;\n    let o=x;\n    let y=0;\n    while(x>0){\n        r = x%10;\n        y = y*10+r;\n        x = Math.floor(x/10);\n    }\n    \n    return y===o;\n};\n\nfunction main(){\n\n}\n\nmain();\n",
   "python": "import math\nclass Solution:\n\tdef isPalindrome(self, x: int) -> bool:\n\t\to = x\n\t\ty = 0\n\t\twhile x > 0:\n\t\t\tr = x % 10\n\t\t\ty = y*10+r\n\t\t\tx = int(math.floor(x/10))\n\t\treturn y == o\n# %%\ns = Solution()\nprint(s.isPalindrome(x = 121))",
   "status": 1,
   "keywords": "数学",
   "license": {
      "cpp": "csdn.net",
      "python": "csdn.net",
      "java": "csdn.net"
   },
   "notebook": {
      "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/8/8_cpp.ipynb?type=file",
      "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/8/8_python.ipynb?type=file",
      "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/8/8_java.ipynb?type=file"
   },
   "notebook_enable": 1
}