题解 | #删除公共字符#

https://www.nowcoder.com/practice/f0db4c36573d459cae44ac90b90c6212

import java.util.*;
public class Main{
    public static void main(String [] args){
    Scanner sc=new Scanner(System.in);
    String str1= sc.nextLine();
    String str2= sc.nextLine();
    HashMap<Character,Integer> map=new HashMap<>();    
     for(int i=0; i<str2.length();i++){
         if(map.get(str2.charAt(i))==null){
             map.put(str2.charAt(i),1);
         }else{
             map.put(str2.charAt(i),map.get(str2.charAt(i))+1);
         }
     }
    String ret="";
       for(int j=0;j<str1.length();j++){
           if(map.get(str1.charAt(j))==null){
               ret+=str1.charAt(j);
           }
       }
    System.out.println(ret);
    }
 }

map去重输出即可
全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 18:25
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务