Set 是唯一值的集合。
每个值在 Set 中只能出现一次。
一个 Set 可以容纳任何数据类型的任何值。
Set的大小 == 字符串长度 ——>字符串中每个字符都唯一
/**
* @param {string} astr
* @return {boolean}
*/
var isUnique = function(astr) {
return astr.length == new Set(astr).size;
};
作者:biemx
链接:https://leetcode-cn.com/problems/is-unique-lcci/solution/tou-lan-ye-neng-ji-bai-100-by-biemx-4jdp/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。