Fork me on GitHub

Lintcode 157. 判断字符串是否没有重复字符

------------------------

 

因为字符究竟是什么样的无法确定(比如编码之类的),恐怕是没办法假设使用多大空间(位、数组)来标记出现次数的,集合应该可以但感觉会严重拖慢速度...

还是只做出了O(n^2)...

 

勉强AC代码:

public class Solution {
    /**
     * @param str: a string
     * @return: a boolean
     */
    public boolean isUnique(String s) {
        for(int i=0;i<s.length();i++){
            for(int j=i+1;j<s.length();j++){
                if(s.charAt(i)==s.charAt(j)){
                    return false;
                }
            }
        }
        return true;
    }
}

 

 

题目来源: http://www.lintcode.com/zh-cn/problem/unique-characters/

 

posted @ 2017-01-02 00:10  CC11001100  阅读(386)  评论(0编辑  收藏  举报