Java repeated letter check in string

后端 未结 5 524
余生分开走
余生分开走 2021-01-27 12:43

I\'m having problem figuring out how to check from users input letters that were repeated. Program needs to output repeated letter as true and if there isn\'t any then as false.

5条回答
  •  猫巷女王i
    2021-01-27 13:34

    We can reduce to Single loop with this.

        boolean checkDuplicates(char[] x)
        {
         Set xSet = new HashSet();
           for (char c : x)
           {
            if (xSet.contains(c)) return true;
            xSet.add(i);
           }
         return false;
        }
    

提交回复
热议问题