zoukankan      html  css  js  c++  java
  • 输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。

    package my;
    
    import java.util.HashMap;
    
    public class DelStringSolution {
        //输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。
        //例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”
    
        public String removeString(String str1 ,String str2){
            char[] chars1 = str1.toCharArray();
            char[] chars2 = str2.toCharArray();
            HashMap map = new HashMap<>();
            for(char c : chars2){
                map.put(c,1);
            }
            String result= "";
            for(int i=0 ; i < chars1.length ; i++ ){
                if(map.containsKey(chars1[i])){
                    continue;
                }else {
                    result += chars1[i];
                }
            }
            return result;
        }
        public static void main(String[] args){
            String str1 ="iiti sti di";
            String str2 ="i";
            String ds =new DelStringSolution().removeString(str1,str2);
            System.out.println(ds);
        }
    }
  • 相关阅读:
    TCP之Nagle算法与TCP_NODELAY
    CSPS模拟 87
    CSPS模拟 86
    CSPS模拟 85
    CSPS模拟 84
    CSPS模拟 83
    CSPS模拟 82
    CSPS模拟 81
    CSPS模拟 80
    CSPS模拟 79
  • 原文地址:https://www.cnblogs.com/goodtest2018/p/13662526.html
Copyright © 2011-2022 走看看