Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- System.out.println(firstRepeatedChar("dictionary")); // i
- System.out.println(firstRepeatedChar("abcdefgh")); // null
- }
- public static char firstRepeatedChar(String str){
- if(str.length() < 2){
- return '\0';
- }
- String s = str.toLowerCase(); // Optional
- boolean[] dictionary = new boolean[256];
- for (int i = 0; i < s.length(); i++) {
- char current = s.charAt(i);
- if(!dictionary[current]){
- dictionary[current] = true;
- } else {
- return current;
- }
- }
- return '\0';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement