LeetCode: Short Encoding Of Words Solution

1/**
2 * @param {string[]} words
3 * @return {number}
4 */
5var minimumLengthEncoding = function (words) {
6 words = Array.from(new Set(words))
7 let res = ""
8 outer: for (let i = 0; i < words.length; i++) {
9 for (let j = 0; j < words.length; j++) {
10 if (j !== i && words[j].endsWith(words[i])) {
11 continue outer
12 }
13 }
14 res += words[i] + "#"
15 }
16 return res.length
17}

Comments

Loading comments...

Tags

leetcode

array

string

Apply and earn a $2,500 bonus once you're hired on your first job!

Clients from the Fortune 500 to Silicon Valley startups

Choose your own rate, get paid on time

From hourly, part-time, to full-time positions

Flexible remote working environment

A lot of open JavaScript jobs!!

Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.

Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.

Next Post

LeetCode: Sum Of Beauty Of All Substrings

HoningJS

Search Posts