华为OD机试 -字符串字符匹配(C++ & Java & JS & Python)

描述

判断短字符串S中的所有字符是否在长字符串T中全部出现。

请注意本题有多组样例输入。

数据范围:1≤���(�),���(�)≤200 1≤len(S),len(T)≤200 

进阶:时间复杂度:�(�) O(n) ,空间复杂度:�(�) O(n) 

输入描述:

输入两个字符串。第一个为短字符串,第二个为长字符串。两个字符串均由小写字母组成。

输出描述:

如果短字符串的所有字符均在长字符串中出现过,则输出字符串"true"。否则输出字符串"false"。

示例1

输入:

bc
abc

输出:

true

说明:

其中abc含有bc,输出"true"
 

Java:

import java.util.*;

public class Main {

    public Main() {
    }

    public boolean isAllCharExist(String pShortString, String pLongString) {
        Set<Character> set = new HashSet<>();
        for (char ch : pLongString.toCharArray()) {
            set.add(ch);
        }
        for (char ch : pShortStri

猜你喜欢

转载自blog.csdn.net/m0_68036862/article/details/132873636