solution.json 2.1 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "a29d470cdea24c7ab191ffe82e9aacf6",
  "keywords": "数学",
  "title": "整数反转",
  "desc": [
    {
      "content": "\n<p>给你一个 32 位的有符号整数 <code>x</code> ,返回将 <code>x</code> 中的数字部分反转后的结果。</p><p>如果反转后整数超过 32 位的有符号整数的范围 <code>[−2<sup>31</sup>,  2<sup>31 </sup>− 1]</code> ,就返回 0。</p><strong>假设环境不允许存储 64 位整数(有符号或无符号)。</strong><p> </p><p><strong>示例 1:</strong></p><pre><strong>输入:</strong>x = 123<strong><br />输出:</strong>321</pre><p><strong>示例 2:</strong></p><pre><strong>输入:</strong>x = -123<strong><br />输出:</strong>-321</pre><p><strong>示例 3:</strong></p><pre><strong>输入:</strong>x = 120<strong><br />输出:</strong>21</pre><p><strong>示例 4:</strong></p><pre><strong>输入:</strong>x = 0<strong><br />输出:</strong>0</pre><p> </p><p><strong>提示:</strong></p><ul>\t<li><code>-2<sup>31</sup> <= x <= 2<sup>31</sup> - 1</code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "import math\nclass Solution:\n\tdef reverse(self, x: int) -> int:\n\t\tr = 0\n\t\ty = 0\n\t\tabs_x = abs(x)\n\t\tnegative = x < 0\n\t\twhile abs_x != 0:\n\t\t\tr = abs_x % 10\n\t\t\ty = y*10+r\n\t\t\tabs_x = int(math.floor(abs_x/10))\n\t\tif negative:\n\t\t\ty = -y\n\t\treturn 0 if (y > 2147483647 or y < -2147483648) else y\n# %%\ns = Solution()\nprint(s.reverse(x = 123))\nprint(s.reverse(x = -123))",
    "language": "python"
  },
  "node_id": "dailycode-cc53b8c00c3b47e49acec679ed77a9a8",
  "license": "csdn.net",
  "created_at": 1637894161,
  "topic_link": "https://bbs.csdn.net/topics/600469815"
}