Skip to content

Latest commit

 

History

History
73 lines (48 loc) · 1.25 KB

README_EN.md

File metadata and controls

73 lines (48 loc) · 1.25 KB

中文文档

Description

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

Python3

class Solution:
    def isUnique(self, astr: str) -> bool:
        sets = set(astr)
        return len(sets) == len(astr)

Java

class Solution {
    public boolean isUnique(String astr) {
        char[] chars = astr.toCharArray();
        int len = chars.length;
        for (int i = 0; i < len - 1; ++i) {
            for (int j = i + 1; j < len; ++j) {
                if (chars[i] == chars[j]) {
                    return false;
                }
            }
        }
        return true;
    }
}

...