zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    BlockingQueue
    序列化存取数据库(spring+mybatis+oracle) 以及可能会遇到的数据库取出的数据反序列化失败问题
    关于junit不抛出异常
    关于ByteArrayInputStream、ByteArrayOutputStream 和 ObjectInputStream、ObjectOutputStream
    sc delete mysql命令执行失败
    python中的值传递和引用传递
    flask实现模仿知乎
    协程和装饰器完成简易计算器
    微信JSAPI支付接口,支付完成后关闭当前窗口
    Java关键字transient和volatile小结
  • 原文地址:https://www.cnblogs.com/yunxintryyoubest/p/14182358.html
Copyright © 2011-2022 走看看