We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 39fa4f4 commit b3394c8Copy full SHA for b3394c8
524-longest-word-in-dictionary-through-deleting.js
@@ -19,6 +19,38 @@
19
return res
20
};
21
22
+// another
23
+
24
+/**
25
+ * @param {string} s
26
+ * @param {string[]} dictionary
27
+ * @return {string}
28
+ */
29
+const findLongestWord = function (s, dictionary) {
30
+ const n = dictionary.length
31
+ const idxArr = Array(n).fill(0)
32
+ let res = ''
33
+ for (const ch of s) {
34
+ for (let i = 0; i < n; i++) {
35
+ const idx = idxArr[i]
36
+ if (idx >= dictionary[i].length) continue
37
+ if (ch === dictionary[i][idx]) {
38
+ idxArr[i]++
39
+ }
40
41
+ if (
42
+ idxArr[i] === dictionary[i].length &&
43
+ (dictionary[i].length > res.length ||
44
+ (dictionary[i].length === res.length && dictionary[i] < res))
45
+ ) {
46
+ res = dictionary[i]
47
48
49
50
+ return res
51
+}
52
53
54
// another
55
56
/**
0 commit comments