Skip to content

Instantly share code, notes, and snippets.

@maoxiaoke
Last active February 21, 2022 15:47
Show Gist options
  • Select an option

  • Save maoxiaoke/660f545ed97fb44bc4dedee391b214ec to your computer and use it in GitHub Desktop.

Select an option

Save maoxiaoke/660f545ed97fb44bc4dedee391b214ec to your computer and use it in GitHub Desktop.

Revisions

  1. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 0 additions and 24 deletions.
    24 changes: 0 additions & 24 deletions __Base__---全排列算法.js
    Original file line number Diff line number Diff line change
    @@ -1,24 +0,0 @@
    /**
    * Heap's algorithm
    */

    function heapPermutation(arr,size,n){
    var swap = function (index1,index2) {
    var temp = arr[index1];
    arr[index1] = arr[index2];
    arr[index2] = temp;
    }
    if (size === 1){
    console.log(arr);
    return;
    }
    for (let i = 0; i < size; i++){
    heapPermutation(arr, size -1,n);

    swap(size % 2 ? 0 : i, size - 1);
    }
    }

    var arr = ['a','b','c','d'];

    heapPermutation(arr,arr.length,arr.length);
  2. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions __Base__---辗转相除法求最大公约数.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    // 递归
    function gcd(m ,n){
    if(n) return gcd(n,m%n);
    return m;
    }
  3. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 18 additions and 1 deletion.
    19 changes: 18 additions & 1 deletion __LeetCode__ ---查找所有的素数.js
    Original file line number Diff line number Diff line change
    @@ -1 +1,18 @@
    ‎‎
    var prime = function(num){
    var i,j;
    var arr = [];

    for(i = 1; i < num; i++){
    for(j=2; j < i; j++){
    if(i%j === 0) {
    break;
    }
    }

    if(i <= j && i !=1){
    arr.push(i);
    }

    }
    return arr;
    };
  4. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions __LeetCode__ ---查找所有的素数.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎
  5. maoxiaoke revised this gist Feb 21, 2022. 2 changed files with 29 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions __LeetCode__ ---全排列算法.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    /**
    * Heap's algorithm
    */

    function heapPermutation(arr,size,n){
    var swap = function (index1,index2) {
    var temp = arr[index1];
    arr[index1] = arr[index2];
    arr[index2] = temp;
    }
    if (size === 1){
    console.log(arr);
    return;
    }
    for (let i = 0; i < size; i++){
    heapPermutation(arr, size -1,n);

    swap(size % 2 ? 0 : i, size - 1);
    }
    }

    var arr = ['a','b','c','d'];

    heapPermutation(arr,arr.length,arr.length);
    5 changes: 5 additions & 0 deletions __LeetCode__ ---辗转相除法求最大公约数.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    // 递归
    function gcd(m ,n){
    if(n) return gcd(n,m%n);
    return m;
    }
  6. maoxiaoke revised this gist Feb 21, 2022. 2 changed files with 0 additions and 29 deletions.
    24 changes: 0 additions & 24 deletions __LeetCode__---全排列算法.js
    Original file line number Diff line number Diff line change
    @@ -1,24 +0,0 @@
    /**
    * Heap's algorithm
    */

    function heapPermutation(arr,size,n){
    var swap = function (index1,index2) {
    var temp = arr[index1];
    arr[index1] = arr[index2];
    arr[index2] = temp;
    }
    if (size === 1){
    console.log(arr);
    return;
    }
    for (let i = 0; i < size; i++){
    heapPermutation(arr, size -1,n);

    swap(size % 2 ? 0 : i, size - 1);
    }
    }

    var arr = ['a','b','c','d'];

    heapPermutation(arr,arr.length,arr.length);
    5 changes: 0 additions & 5 deletions __LeetCode__---辗转相除法求最大公约数.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    // 递归
    function gcd(m ,n){
    if(n) return gcd(n,m%n);
    return m;
    }
  7. maoxiaoke revised this gist Feb 21, 2022. 2 changed files with 29 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions __LeetCode__---全排列算法.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    /**
    * Heap's algorithm
    */

    function heapPermutation(arr,size,n){
    var swap = function (index1,index2) {
    var temp = arr[index1];
    arr[index1] = arr[index2];
    arr[index2] = temp;
    }
    if (size === 1){
    console.log(arr);
    return;
    }
    for (let i = 0; i < size; i++){
    heapPermutation(arr, size -1,n);

    swap(size % 2 ? 0 : i, size - 1);
    }
    }

    var arr = ['a','b','c','d'];

    heapPermutation(arr,arr.length,arr.length);
    5 changes: 5 additions & 0 deletions __LeetCode__---辗转相除法求最大公约数.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    // 递归
    function gcd(m ,n){
    if(n) return gcd(n,m%n);
    return m;
    }
  8. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion __Base__---辗转相除法求最大公约数.js
    Original file line number Diff line number Diff line change
    @@ -1 +1,5 @@
    ‎‎
    // 递归
    function gcd(m ,n){
    if(n) return gcd(n,m%n);
    return m;
    }
  9. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions __Base__---辗转相除法求最大公约数.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎
  10. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion __Base__---index.js
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    ‎‎
  11. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 24 additions and 1 deletion.
    25 changes: 24 additions & 1 deletion __Base__---全排列算法.js
    Original file line number Diff line number Diff line change
    @@ -1 +1,24 @@
    ‎‎
    /**
    * Heap's algorithm
    */

    function heapPermutation(arr,size,n){
    var swap = function (index1,index2) {
    var temp = arr[index1];
    arr[index1] = arr[index2];
    arr[index2] = temp;
    }
    if (size === 1){
    console.log(arr);
    return;
    }
    for (let i = 0; i < size; i++){
    heapPermutation(arr, size -1,n);

    swap(size % 2 ? 0 : i, size - 1);
    }
    }

    var arr = ['a','b','c','d'];

    heapPermutation(arr,arr.length,arr.length);
  12. maoxiaoke revised this gist Feb 21, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions __Base__---全排列算法.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎
  13. maoxiaoke created this gist Feb 21, 2022.
    1 change: 1 addition & 0 deletions __Base__---index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎