lamiastella

nonrepeating

Apr 10th, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1.  public static char findRepeating(String s){
  2.  
  3.         HashMap<Character, Integer> charCount= new HashMap<>();
  4.         int count=0;
  5.         for (int i=0; i<s.length(); i++){
  6.             if (charCount.containsKey(s.charAt(i))){
  7.                 count=charCount.get(s.charAt(i));
  8.                 charCount.put(s.charAt(i), ++count);
  9.             }
  10.             else{
  11.                 charCount.put(s.charAt(i), 1);
  12.             }
  13.  
  14.         }
  15.         for (Character ch:charCount.keySet()){
  16.             if (charCount.get(ch)==0){
  17.                 return ch;
  18.             }
  19.         }
  20.         return '\0';
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment