Runtime beats 95.88% of javascript submissions.


  • 0
    S

    /**

    • @param {string} s
    • @return {string}
      */
      var frequencySort = function(s) {
      var hashs = {};
      for(var i of s) {
      hashs[i] = (hashs[i] || { key: i, val: 0 });
      hashs[i].val += 1;
      }
      return Object.values(hashs).sort((a, b) => b.val - a.val).map(v => new Array(v.val+1).join(v.key)).join('');
      };

  • 0
    L

    @szer0601 can you please comment your solution? Thanks!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.