当前位置:网站首页>Bull: remove common characters
Bull: remove common characters
2022-07-30 07:42:00 【HDLaZy】
题目描述:

解题思路:
使用Java的HashMap集合框架,HashMap无重复值,将字符串2each character of the,然后遍历字符串1的每一个字符,判断map中是否存在该值,If it does not exist, it will be concatenated into a new string,No splicing if present.
代码:
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);
}
}
边栏推荐
猜你喜欢

05-Theos

Jenkins一些常见问题

Linux(centos7)下安装MySQL

libgrape-lite: 提供 GraphScope 的图分析能力

Redis6的数据类型

prometheus-basic_auth加密配置

Test and Development Engineer Growth Diary 009 - Environment Pai Pai Station: Development Environment, Test Environment, Production Environment, UAT Environment, Simulation Environment

元宇宙与图扑国风的碰撞,科技与文化的虚实融合

Biotin-NH2|CAS:111790-37-5(生物素-氨基)是一种生物素化化合物

prometheus-tls加密
随机推荐
Alamofire源码分析 - POST请求
多线程基础(概念,创建,中断)
instantDrag for Maya脚本 (移动模型时沿目标模型移动)
元宇宙与图扑国风的碰撞,科技与文化的虚实融合
Mastering JESD204B (3) – Debugging of AD6676
测试开发工程师成长日记002 - 从0开始做接口自动化
测试开发工程师成长日记010 - Jenkins中的CI/CD/CT(持续集成构建/持续交付/持续测试)
原力计划微服务实战|集中配置中心Config非对称加密与安全管理
MongoDB-介绍,数据类型,基本语句
图扑数字孪生青岛城轨,赋能智慧交通低碳发展
Alamofire source code analysis - POST request
一种分布式深度学习编程新范式:Global Tensor
使用 Grafana 的 Redis Data Source 插件监控 Redis
Network Protocol 04 - Physical and Data Link Layers
Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)
Test Development Engineer Growth Diary 017 - The Life Cycle of a Bug
MySql connecting to the server remotely
读取GZ包的内容代码
Unable to open socket file: target process not responding or HotSpot VM not loaded
02-Cycript的使用