> For the complete documentation index, see [llms.txt](https://zhongquan789.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zhongquan789.gitbook.io/leetcode/lcci/mian-shi-ti-01.01.md).

# 面试题 01.01

Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?

Example 1:

Input: s = "leetcode" Output: false Example 2:

Input: s = "abc" Output: true

Note:

0 <= len(s) <= 100

## Solutions

1. **bitset**

```cpp
class Solution {
public:
    bool isUnique(string astr) {
        int seen = 0;
        for (auto c : astr)
            if (seen & (1 << (c - 'a')))
                return false;
            else
                seen |= (1 << (c - 'a'));
        return true;
    }
};
```

1. **sort**

```cpp
class Solution {
public:
    bool isUnique(string astr) {
        sort(astr.begin(), astr.end());
        for (int i = 1; i < astr.size(); i++)
            if (astr[i] == astr[i - 1])
                return false;
        return true;
    }
};
```
