fork(1) download
  1. class FirstUniqueCharFinder {
  2.  
  3. static String find(String word) {
  4. int len = word.length();
  5. String firstUniqueChar = null;
  6.  
  7. for (int i = 0; i < len; i++) {
  8. String currentChar = word.substring(i, i + 1);
  9. String after = word.substring(i + 1, len);
  10. if (!after.contains(currentChar)) {
  11. firstUniqueChar = currentChar;
  12. break;
  13. }
  14. }
  15.  
  16. return firstUniqueChar;
  17. }
  18.  
  19. public static void main(String[] args) {
  20. System.out.println(find("transaction"));
  21. System.out.println(find("reverse"));
  22. }
  23. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
r
v