最安値と最高値(レベル2)


1.質問



2.私の回答


def solution(s):
    numbers =[int(num) for num in s.split()]
    min_num = min(numbers)
    max_num = max(numbers)
    return f"{min_num} {max_num}"

3.他人の回答

def solution(s):
    t = []
    if s[0] != "-":
        s = "+" + s
    for i in range(0, len(s)):
        t += [s[i]]
    for i in range(0, len(t)):
        if t[i] == " " and t[i+1] != "-":
            t.insert(i+1, "+")
    for i in range(1, len(t)):
        if t[len(t)-i] == " " and t[len(t)+1-i] != "-":
            t.insert(len(t)+1-i, "+")
            break
    print(t)
    result = []
    midcount1 = ""
    midcount2 = ""
    for i in range(len(t)):

        if t[i] == "-": 
            for j in range(i+1, len(t)):
                if t[j] != " ":
                    midcount1 = midcount1 + t[j]
                    if j == len(t)-1:
                        result += [-int(midcount1)]
                        midcount1 = ""
                        break
                elif t[j] == " ":
                    print(midcount1)
                    result += [-int(midcount1)]
                    midcount1 = ""
                    break

        elif t[i] == "+":
            for j in range(i+1, len(t)):
                if t[j] != " ":
                    midcount2 = midcount2 + t[j]
                    if j == len(t)-1:
                        result += [int(midcount2)]
                        midcount2 = ""
                        break
                elif t[j] == " ":
                    print(midcount2)
                    result += [int(midcount2)]
                    midcount2 = ""
                    break


    print(result)
    resultmax = int(result[0])
    resultmin = int(result[0])
    for i in range(len(result)):
        if resultmax < result[i]:
            resultmax = result[i]
    for i in range(len(result)):
        if resultmin > result[i]:
            resultmin = result[i]
    return "%s %s" % (resultmin, resultmax)

4.感じ