Simple CoffeeScript Solution, few lines


  • 0
    M
    letterWordMatch = (pattern, str) ->
      [letterGroups, wordGroups, letterArr, wordArr] = [[], [], pattern.split(''), str.split(' ')]
      return no if letterArr.length isnt wordArr.length
      for l in letterArr
        letterGroups.push(l) unless l in letterGroups
      for w in wordArr
        wordGroups.push(w) unless w in wordGroups
      letterGroups.length is wordGroups.length

Log in to reply
 

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