Easiest way of checking if a string consists of unique characters?

前端 未结 12 1743
慢半拍i
慢半拍i 2021-01-04 23:34

I need to check in Java if a word consists of unique letters (case insensitive). As straight solution is boring, I came up with:

  1. For every char in a string che
12条回答
  •  天涯浪人
    2021-01-05 00:12

    Here's the code I wrote for Kache's answer(referred from cracking the code and modified):

    public boolean check() {
        int[] checker = new int[8];
        String inp = "!a~AbBC#~";
        boolean flag = true;
        if (inp.length() > 256)
            flag = false;
        else {
            for(int i=0;i 0) { 
                    flag = false;
                    break;
                }
                else
                    checker[index] = checker[index] | 1<

提交回复
热议问题