Algorithm/Programmers

[Programmers] 코딩 기초 트레이닝 #6

j4ko 2023. 11. 27. 23:20
728x90
반응형

목차

     

    뒤에서 5등까지

    https://school.programmers.co.kr/learn/courses/30/lessons/181853

    def solution(num_list):
        num_list.sort()
        return num_list[:5]
    

     

    홀수 vs 짝수

    https://school.programmers.co.kr/learn/courses/30/lessons/181887

    def solution(num_list):
        odd_numeber = 0
        even_number = 0
        for idx, value in enumerate(num_list, start=1):
            if idx % 2 != 0:
                odd_numeber += value
            if idx % 2 == 0:
                even_number += value
    
        return max(odd_numeber, even_number)
    

     

    할일 목록

    https://school.programmers.co.kr/learn/courses/30/lessons/181887

    def solution(todo_list, finished):
        answer = []
        for v1, v2 in zip(todo_list, finished):
            if not v2:
                answer.append(v1)            
        return answer
    

     

    공백으로 구분하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181868

    def solution(my_string):
        return my_string.split()
    

     

    x 사이의 개수

    https://school.programmers.co.kr/learn/courses/30/lessons/181867

    def solution(myString):
        answer = []
        for x in myString.split("x"):
            answer.append(len(x))
        return answer
    

     

    부분 문자열인지 확인하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181843

    def solution(my_string, target):
        if target in my_string:
            return 1
        return 0
    

     

    두 수의 연산값 비교하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181938

    def solution(a, b):
        cond1 = str(a) + str(b)
        cond2 = 2 * a * b
        return max(int(cond1), cond2)
    

     

    배열 비교하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181856

    def solution(arr1, arr2):
        sum_arr1 = sum(arr1)
        sum_arr2 = sum(arr2)
    
        if len(arr1) < len(arr2):
            return -1
        
        if len(arr1) > len(arr2):
            return 1
    
        if len(arr1) == len(arr2):
            if sum_arr1 < sum_arr2:
                return -1
            elif sum_arr1 == sum_arr2:
                return 0
            elif sum_arr1 > sum_arr2:
                return 1
    

     

    부분 문자열

    https://school.programmers.co.kr/learn/courses/30/lessons/181842

    def solution(str1, str2):
        return int(str1 in str2)
    

     

    원하는 문자열 찾기

    https://school.programmers.co.kr/learn/courses/30/lessons/181878

    def solution(myString, pat):        
        return int(pat.lower() in myString.lower())
    
    728x90
    반응형