Skip to content

Instantly share code, notes, and snippets.

@Angelfire
Last active May 7, 2022 23:25
Show Gist options
  • Select an option

  • Save Angelfire/5c7ea31c7141ccb25054db661cda0d1f to your computer and use it in GitHub Desktop.

Select an option

Save Angelfire/5c7ea31c7141ccb25054db661cda0d1f to your computer and use it in GitHub Desktop.

Revisions

  1. Angelfire revised this gist May 10, 2021. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions stringReduction.js
    Original file line number Diff line number Diff line change
    @@ -10,3 +10,26 @@ function getMinDeletions(s) {

    return delCount;
    }



    function getMinDeletionsSet(str){
    let strSet = new Set(str);

    return str.length - strSet.size;
    }



    function getMinDeletionsArrayFrom(str) {
    const sortedStr= Array.from(str).sort();
    let delCount = 0;

    for (let i = 0; i < sortedStr.length; i++) {
    if (sortedStr[i] === sortedStr[i + 1]) {
    delCount++;
    }
    }

    return delCount;
    }
  2. Angelfire created this gist May 8, 2021.
    12 changes: 12 additions & 0 deletions stringReduction.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    function getMinDeletions(s) {
    const ordered_string = s.split('').sort().join('');
    let delCount = 0;

    for (let i = 0; i < ordered_string.length; i++) {
    if (ordered_string[i] === ordered_string[i + 1]) {
    delCount++;
    }
    }

    return delCount;
    }