- 巧解
for(let s of str){ if(str.indexOf(s) === str.lastIndexOf(s)){ return str.indexOf(s); } } return -1;
- 使用哈希表
https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/solution/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-by-3zqv5/
for(let s of str){ if(str.indexOf(s) === str.lastIndexOf(s)){ return str.indexOf(s); } } return -1;