Title / Description
Code class C1_1 { public static void main(String[] args) { System.out.println(isUnique("fayimora")); System.out.println(isUnique("fayi")); System.out.println(isUnique("aaaaaaaa")); System.out.println(isUnique("")); System.out.println(isUnique(" ")); System.out.println("\n\nUNIQUED"); System.out.println(isUniqueD("fayimora")); System.out.println(isUniqueD("fayi")); System.out.println(isUniqueD("aaaaaaaa")); System.out.println(isUniqueD("")); System.out.println(isUniqueD(" ")); } public static boolean isUnique(String word) { int length = word.length(); if(length==0) return true; for(int i=0; i<length; i++) { char a = word.charAt(i); for(int j=i+1; j<length; j++) { char b = word.charAt(j); if(a==b) return false; } } return true; } public static boolean isUniqueD(String word) { boolean[] ascii = new boolean[256]; for(int i=0; i<word.length(); i++) { int val = word.charAt(i); if(ascii[val]) return false; ascii[val]=true; } return true; } }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code