-
-
Save gaoyike/bedec0889b830a813902 to your computer and use it in GitHub Desktop.
1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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