拼多多笔试,第二题编程题75%
拼多多笔试,第二题编程题,求问,为什么我的是75%,我能想到的用例都能测试通过啊!!!!
代码实现如下:
import java.util.*;
/**
* Created by lalala on 2019/3/10.
* 注释:字符去重后,找到首个字母最小值
*/
public class Second {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
if (str == null || str.trim().length() == 0){
System.out.println("");
return;
}
str = str.toLowerCase();
LinkedHashMap<Character,Integer> map = new LinkedHashMap<Character,Integer>();
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (map.containsKey(ch)){
map.put(ch, (Integer) map.get(ch)+1);
}else {
map.put(ch, 1);
}
}
char firstMin='z';
Iterator iterator=map.entrySet().iterator();
while(iterator.hasNext()){
Map.Entry entry=(Map.Entry )iterator.next();
char ch = (char)entry.getKey();
if (firstMin > ch){
firstMin =ch;
}
int value = (int)entry.getValue();
if (value == 1){
break;
}else{
map.put(ch,value--);
}
}
System.out.println(firstMin);
}
}
#拼多多#