var findLUSlength = function(strs) { let map = {}, max = 0, str // 哈希表计数 并且寻找最长字符串 for (let i = strs.length - 1; i >= 0; i--) { map[strs[i]] ? map[strs[i]]++ : map[strs[i]] = 1 if (strs[i].length > max) { max = strs[i].length str = strs[i] } } // 最长字符串是唯一的 if (map[str] == 1) { return max } max = -1 // 双指针比较 let compare = function (target, origin) { let i = 0, j = 0, n = target.length, m = origin.length while (i < n && j < m) { if (origin[j] == target[i]) j++ i++ } return j == m } // 取出哈希表中的唯一的字符串与str(最长的字符串)进行比较 判断是否为它的子串 for (let key in map) { if (map[key] == 1 && !compare(str, key)) { max = Math.max(key.length, max) } } return max };