字符串
1、找出字符流中第一个只出现一次的字符
第一个:能保持顺序
重复:hashmap/set
思路:用list来保证顺序,hashmap保存字符和其出现次数
import java.util.*;
public class Solution {
public static Map<Character,Integer> map=new HashMap<>();
ArrayList<Character> queue=new ArrayList<Character>();
public void Insert(char ch)
{
//重复+1,不重入
if(!map.containsKey(ch)){
map.put(ch,1);
queue.add(ch);
}
else map.put(ch,map.get(ch)+1);
}
public char FirstAppearingOnce()
{
for(char c:queue){
if(map.get(c)==1)
return c;
}
return '#';
}
}
基恩士成长空间 453人发布
