• 1705. 比较字符串 II


    1705. 比较字符串 II

    中文English

    One string is strictly smaller than another when the frequency of occurrence of the smallest character in the string is less than the frequency of occurrence of the smallest character in the comparison string.
    For example,string "abcd" is smaller than string "aaa" because the smallest character (in lexicographical order) in "abcd" is 'a', with a frequency of 1, and the smallest character in "aaa" is also 'a',but with a frequency of 3. In another example, string "a" is smaller than string "bb" beacuse the smallest character in "a" is 'a' with a frequency of 1, and the smallest character in "bb" is 'b' with a frequency of 2.
    Write a function that, given string A (which contains N strings delimited by ','), returns an array C of N integers. For 0 <= J < N, values of C[J] specify the number of strings in A which are strictly smaller than the comparison J-th string in B (starting from 0).

    样例

    Example 1:

    Input: 
    A = "abcd,aabc,bd"
    B = "aaa,aa"
    Output: [3, 2]	
    Explanation: All the strings in the array are strictly smaller than "aaa" on the basis of the given comparison cirteria;
    Strings "abcd" and "bd" are strictly smaller than "aa".
    

    注意事项

    • 1 <= N, M <= 10000
    • 1 <= length of any string contained by A or B <= 10
    class Solution:
        """
        @param A: a string
        @param B: a string
        @return: returns an array C of N integers
        """
        def compareStringii(self, A, B):
            # write your code here
            if not A or not B: return [] 
    
            results = []
            A_array, B_array = [val for val in A.split(',')], [val for val in B.split(',')]
            A_count, B_count = [], []
    
            for val in A_array:
                temp_array = [v for v in val]
                A_count.append(temp_array.count(min(temp_array)))
    
            for val in B_array:
                temp_array = [v for v in val]
                B_count.append(temp_array.count(min(temp_array)))
    
            for j in B_count:
                count = 0
    
                for i in A_count:
                    if i < j:
                        count += 1 
                results.append(count)
    
            return results
  • 相关阅读:
    CCCC 2020 酱油记
    CCPC 2020 威海 滚粗记
    IEEExtreme 2020 酱油记
    CCSP 2020 酱油记
    ICPC 陕西省赛 2020 游记
    CCPC 网络赛 2020 自闭记
    CSP 第20次认证 酱油记
    CSP-S 2019 酱油记
    NOI2019 退役记
    树链剖分入门
  • 原文地址:https://www.cnblogs.com/yunxintryyoubest/p/14182358.html
Copyright © 2020-2023  润新知