aboutsummaryrefslogtreecommitdiff
path: root/challenge-280/deadmarshal/java/Ch1.java
blob: 678ee12336a5a8789e4b424fd10786dad272d10a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class Ch1 {
  public static void main(String[] args) {
    System.out.println(twice_appearance("acbddbca"));
    System.out.println(twice_appearance("abccd"));
    System.out.println(twice_appearance("abcdabbb"));
  }

  private static char twice_appearance(String str) {
    int[] counts = new int[26];
    for (int i = 0; i < str.length(); ++i) {
      int idx = str.charAt(i) - 'a';
      if (counts[idx] != 0) return str.charAt(i);
      counts[idx]++;
    }
    return '\0';
  }
}