> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/letcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/letcode/2.algorithm/2.1.backtracking/211lian-xu-xu-lie-de-pai-lie-zu-540828-ke-neng-hui-zhong-890729.md).

# 2.1.1.連續序列的排列組合(可能會重複)

* Example code:

  ```
       /**
       * Return an array of arrays of size *returnSize.
       * Note: The returned array must be malloced, assume caller calls free().
       */
      int fact(int n)
      {
          if (n==0) {
              return(1);
          }
          else {
              return(n*fact(n-1));
          }
      }
       void save(int* temp, int N, int ** res, int * index)
      {
          for (int i=0; i<N; ++i) {
              //printf("%d",temp[i]);
              res[*index][i] = temp[i];
          }
          *index = *index + 1;
      }

      void backtrack(int* nums, int* temp, int* used, int n, int N, int ** res, int * index)
      {
          if (n == N) {
              save(temp, N, res, index);
              return;
          }

          for (int i=0; i < N; i++){
              if (!used[i])
              {
                  used[i] = 1;
                  temp[n] = nums[i];
                  backtrack(nums, temp, used, n+1, N, res, index);
                  used[i] = 0;
              }
          }
      }
      void enumerate_permutations(int* nums, int* temp, int* used, int N, int ** res)
      {
          for (int i=0; i<N; i++) {
              used[i] = 0;
          }
          int index =0;
          backtrack(nums, temp, used, 0, N, res, &index);
      }
      int** permute(int* nums, int numsSize, int* returnSize) 
      {
          int length = fact(numsSize);
          int ** ary = (int **) malloc (length * sizeof(int *));
          for (int i=0; i< length; i++){
              ary[i] = (int *)malloc(numsSize * sizeof(int));
          }
          int* used = (int *)malloc(numsSize * sizeof(int));
          int* temp = (int *)malloc(numsSize * sizeof(int));
          *returnSize = length;
          enumerate_permutations(nums, temp, used, numsSize, ary);

          return ary;    

      }
  ```
