Skip to content

Commit c58ad69

Browse files
authored
Create 1554-strings-differ-by-one-character.js
1 parent b1155a8 commit c58ad69

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {string[]} dict
3+
* @return {boolean}
4+
*/
5+
const differByOne = function(dict) {
6+
const n = dict.length, m = dict[0].length
7+
for (let j = 0; j < m; j++) {
8+
const seen = new Set()
9+
for(let i = 0; i < n; i++) {
10+
const newStr = dict[i].slice(0, j) + '*' + dict[i].slice(j + 1)
11+
if(seen.has(newStr)) return true
12+
seen.add(newStr)
13+
}
14+
}
15+
16+
return false
17+
};

0 commit comments

Comments
 (0)