Skip to content

Instantly share code, notes, and snippets.

@gaoyike
Created June 15, 2014 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaoyike/bedec0889b830a813902 to your computer and use it in GitHub Desktop.
Save gaoyike/bedec0889b830a813902 to your computer and use it in GitHub Desktop.
1.1
/**
* Created by Readman on 6/15/14.
*/
public class UniqueString {
/*
time: N, traverse all char in String
space: since boolean [] take up to 256 (assume ascii) 1
* */
public static boolean uniqueString (String s) {
return rec(s, new boolean[256]);
}
public static boolean rec (String s, boolean[] test) {
if (s.isEmpty()) {
return true;
}
if (test[s.charAt(0)])
{
return false;
}
else {
test[s.charAt(0)] = true;
}
return rec (s.substring(1), test);
}
public static void main(String[] args) {
String s = "";
System.out.println(uniqueString(s));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment