利用map进行查重

import java.util.*;
public class Solution {
    //Insert one char from stringstream
    String str = "";
    public void Insert(char ch)
    {
        str = str +  ch;
    }
  //return the first appearence once char in current stringstream
    public char FirstAppearingOnce()
    {
        Map<String,Integer> we = new HashMap<>();
        String[] list = str.split("");
        int op = 0;
        int k = 0;
        char w = '#';
        for(String i : list){
            if(we.containsKey(i)){
                we.put(i,we.get(i)+1);
            }else{
                we.put(i,1);
            }
        }
        for(int i=0;i<list.length;i++){
            if(we.get(list[i]) == 1){
                op = 1;
                k =i;
                break;
            }
        }
        if(op == 0){
            return '#';
        }else{
            return str.charAt(k);
        }
    }
}