当前位置:网站首页>牛客:删除公共字符
牛客:删除公共字符
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);
}
}
边栏推荐
- led闪烁
- Shortcut keys commonly used in the use of Word
- ThreeJS导入外部obj和mtl
- 【动态规划】LeetCode刷题清单及思路记录
- GNNLab: A Novel GNN System Based on Spatial Sharing Ideas
- 掌握JESD204B(三)–AD6676的调试
- 快速开发 GraphScope 图分析应用
- 单片机第一步
- GAIA-IR: Parallelized Graph Query Engine on GraphScope
- Vineyard: An open source distributed in-memory data management framework
猜你喜欢

Shortcut keys commonly used in the use of Word

VsCode connects to the remote server and modifies the file code

instantDrag for Maya脚本 (移动模型时沿目标模型移动)

基于 JupyterLab 插件在 GraphScope 中交互式构图

阿里京东“喜提”国电投,顶流互联网和能源大厂为何合作?

IO进程线程->标准IO->day1

单片机第一步

Unity 渲染流水线

How to create a shortcut without the "shortcut" suffix?

Mastering JESD204B (3) – Debugging of AD6676
随机推荐
04-加壳和脱壳
从安装到编译: 10分钟教你在本地使用和开发GraphScope
GNNLab: A Novel GNN System Based on Spatial Sharing Ideas
力扣题解7.27
一种新的DNA生物素系统Biotin LC hydrazide|CAS:109276-34-8|(+)-生物素酰胺基己酸肼
SQL并列排序问题
The most complete difference between sizeof and strlen, as well as pointer and array operation analysis
Biotinyl Cystamine_CAS:128915-82-2_生物素半胱胺
【无标题】
图计算在网络安全分析中的应用
比尔·盖茨买百万亩农地成美“头号地主”,图扑数字孪生农场
flask项目快速搭建部署gunicorn+supervisor
网络协议03 - 路由和NAT
元宇宙与图扑国风的碰撞,科技与文化的虚实融合
Network Protocol 04 - Physical and Data Link Layers
libgrape-lite on GPUs:GPU助力加速图分析任务
OP tokens and non-transferable NFTs work to build a new digital democracy
THREEJS辉光与景深特效
A New Paradigm for Distributed Deep Learning Programming: Global Tensor
How to save modelsim simulation data as a file