Skip to content

Latest commit

 

History

History
20 lines (15 loc) · 323 Bytes

01.01. 判定字符是否唯一.md

File metadata and controls

20 lines (15 loc) · 323 Bytes

代码

var isUnique = function(astr) {
  let res = 0;
  for(let i = 0; i < astr.length; i ++) {
    let cur = astr[i].charCodeAt() - 97;
    if ((res & (1 << cur)) !== 0) return false
    res |= (1 << cur)
  }
  return true;
};

复杂度分析

时间复杂度 $O(N)$

空间复杂度 $O(1)$