solution.json 2.5 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": "1ad31701c625447eb34e16636233d8c5",
  "keywords": "数组,双指针",
  "title": "下一个排列",
  "desc": [
    {
      "content": "\n<p>实现获取 <strong>下一个排列</strong> 的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列。</p><p>如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排列)。</p><p>必须<strong><a href=\"https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95\" target=\"_blank\"> 原地 </a></strong>修改,只允许使用额外常数空间。</p><p> </p><p><strong>示例 1:</strong></p><pre><strong>输入:</strong>nums = [1,2,3]<strong><br />输出:</strong>[1,3,2]</pre><p><strong>示例 2:</strong></p><pre><strong>输入:</strong>nums = [3,2,1]<strong><br />输出:</strong>[1,2,3]</pre><p><strong>示例 3:</strong></p><pre><strong>输入:</strong>nums = [1,1,5]<strong><br />输出:</strong>[1,5,1]</pre><p><strong>示例 4:</strong></p><pre><strong>输入:</strong>nums = [1]<strong><br />输出:</strong>[1]</pre><p> </p><p><strong>提示:</strong></p><ul>\t<li><code>1 <= nums.length <= 100</code></li>\t<li><code>0 <= nums[i] <= 100</code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "class Solution {\n\tpublic void nextPermutation(int[] nums) {\n\t\tint i = nums.length - 1;\n\t\twhile (i > 0 && nums[i] <= nums[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i > 0) {\n\t\t\tint j = nums.length - 1;\n\t\t\twhile (j >= 0 && nums[j] <= nums[i - 1]) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tswap(nums, i - 1, j);\n\t\t}\n\t\treverse(nums, i);\n\t}\n\tprivate void reverse(int[] nums, int i) {\n\t\tint j = nums.length - 1;\n\t\twhile (i < j) {\n\t\t\tswap(nums, i, j);\n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n\tprivate void swap(int[] nums, int i, int j) {\n\t\tint temp = nums[i];\n\t\tnums[i] = nums[j];\n\t\tnums[j] = temp;\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-06979d4bde9b4d048a028977d9bee368",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600471007"
}