알고리즘 문제/CodeWar
Two to One
BEstyle
2022. 9. 14. 22:52
9월 14일
Take 2 strings s1 and s2 including only letters from a to 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"
def longest(a1, a2):
alist=[]
for letter in a1:
if letter not in alist:
alist.append(letter)
for letter in a2:
if letter not in alist:
alist.append(letter)
alist.sort()
print(alist)
str=""
for letter in alist:
str+=letter
print(str)
return str