Java实现-判断字符串是否没有重复字符

来源:互联网 发布:淘宝上的货源怎么找 编辑:程序博客网 时间:2024/05/23 01:17

实现一个算法确定字符串中的字符是否均唯一出现

样例

给出"abc",返回 true

给出"aab",返回 false

public class Solution {    /**     * @param str: a string     * @return: a boolean     */    public boolean isUnique(String str) {        // write your code here        if(str.length()==0)return false;Set<Character> set=new HashSet<Character>();for(int i=0;i<str.length();i++){set.add(str.charAt(i));}if(set.size()==str.length())return true;return false;    }}


阅读全文
0 0
原创粉丝点击