标签:code for 构造 min 封装 ted ati 不同 from
Codewars 刷题第一天,字符串问题:
题目:
Take 2 strings s1 and s2 including only letters from ato z.
Return a new sorted string, the longest possible, containing distinct letters,each taken only once - coming from s1 or s2.
#Examples: ``` a = "xyaabbbccccdefww" b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"
a = "abcdefghijklmnopqrstuvwxyz"
longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" ```
题目要求:构造longest(String a,String b)函数,输出String a,String b 中所有出现过的字符,且只输出一次,并且按照字母表的顺序。
解析:字符串的但单个字符遍历,然后将出现的不同的ASII码的值存下来,再进行排序输出!
答案(1)
答案(2) 中,应用了大家喜闻乐见的Collector收集齐,告别for循环,拼接字符串。对s1+s2进行map封装,distinct去重。
标签:code for 构造 min 封装 ted ati 不同 from
原文地址:https://www.cnblogs.com/Jaiken/p/8878696.html