当前位置:网站首页>牛客:删除公共字符
牛客:删除公共字符
2022-07-30 05:48:00 【HDLaZy】
题目描述:

解题思路:
使用Java的HashMap集合框架,HashMap无重复值,将字符串2的每一个字符存入其中,然后遍历字符串1的每一个字符,判断map中是否存在该值,如果不存在则拼接到新的字符串中,如果存在则不进行拼接。
代码:
import java.util.*;
public class Main{
public static void main (String[] args){
Scanner scan = new Scanner(System.in);
String str1 = scan.nextLine();
String str2 = scan.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 result="";
for(int i=0; i< str1.length() ; i++){
if(map.get(str1.charAt(i))==null){
result+=str1.charAt(i);
}
}
System.out.println(result);
}
}
边栏推荐
猜你喜欢

Mastering JESD204B (3) – Debugging of AD6676

04-加壳和脱壳

图扑数字孪生煤矿开采系统,打造采煤“硬实力”

GAIA-IR: Parallelized Graph Query Engine on GraphScope

GNNLab: A Novel GNN System Based on Spatial Sharing Ideas

libgrape-lite on GPUs: GPU helps accelerate graph analysis tasks

基于精灵(Sprite)管道烟雾流动效果

Build an intelligent network security management and control system for digital government

图扑数字孪生北京故宫,推进旅游业元宇宙进程

Unity 渲染流水线
随机推荐
Devops基本概念和原理
Unity 渲染流水线
不依赖框架的文件下载
Biotin-NHS LC(72040-63-2)生物素接头|站点特定探针
GNNLab: A Novel GNN System Based on Spatial Sharing Ideas
元宇宙与图扑国风的碰撞,科技与文化的虚实融合
How to save modelsim simulation data as a file
GAIA-IR:GraphScope 上的并行化图查询引擎
陕西Biotin-LC_CAS:72040-64-3_N-生物素氨基己酸供应商价格
Delete all files containing a keyword in the current path
GCD的定时器
c语言编程练习
Biotin-PEG4-DADPS-Picolyl-azide(CAS:2599839-59-3)生物素试剂
com.alibaba.datax.common.exception.DataXException: Code:[ESWriter-03]
实现二叉树--实现删除
基于STM32F103的消防系统之驱动电机风扇
(*(void (*)())0)() Interpretation
使用 Helm 部署 GraphScope
掌握JESD204B(三)–AD6676的调试
比尔·盖茨买百万亩农地成美“头号地主”,图扑数字孪生农场