-
반응형
잘라서 배열로 저장하기 - https://school.programmers.co.kr/tryouts/85905/challenges
간단한 한줄 문제
def solution(my_str, n): return [my_str[start:start+n] for start in range(0, len(my_str), n)]
2차원으로 만들기 - https://school.programmers.co.kr/tryouts/85906/challenges
위와 동일한 문제
def solution(num_list, n): return [num_list[start:start+n] for start in range(0, len(num_list), n)]
7의 개수 - https://school.programmers.co.kr/tryouts/85907/challenges
정수 배열을 map 사용해서 형변환 해준 뒤 문자열로 만들고 count해줌
def solution(array): return "".join(map(str, array)).count("7")
가장 큰 수 찾기 - https://school.programmers.co.kr/tryouts/85908/challenges
max 메소드 사용해서 최댓값 찾고, index 메소드로 인덱스 찾음
def solution(array): max_num = max(array) return [max_num,array.index(max_num)]
모의고사 - https://school.programmers.co.kr/tryouts/85909/challenges
패턴 작성한 뒤에 순차적으로 스코어 기록하고 max 메소드로 우승자 선정
def solution(answers): p1 = [1, 2, 3, 4, 5] p2 = [2, 1, 2, 3, 2, 4, 2, 5] p3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] score = [0, 0, 0] for i in range(len(answers)): if answers[i] == p1[i % len(p1)]: score[0] += 1 if answers[i] == p2[i % len(p2)]: score[1] += 1 if answers[i] == p3[i % len(p3)]: score[2] += 1 max_score = max(score) return [idx + 1 for idx, s in enumerate(score) if s == max_score]
행렬의 덧셈 - https://school.programmers.co.kr/tryouts/85910/challenges
처음에 이차원 리스트 초기화하는게 포인트
def solution(arr1, arr2): answer = [[0 for _ in range(len(arr1[0]))]for _ in range(len(arr1))] for i in range(len(arr1)): for j in range(len(arr1[0])): answer[i][j] = arr1[i][j] + arr2[i][j] return answer
바탕화면 정리 - https://school.programmers.co.kr/tryouts/85911/challenges
전체 순회하면서 시작점과 끝점을 찾음. #이 없는 열은 넘겨서 속도를 높여줌
def solution(wallpaper): answer = [] sx, sy = 51, 51 ex, ey = -1, -1 for i, item in enumerate(wallpaper): if item.count("#") == 0: continue for j, c in enumerate(item): if c == "#": if sx > i: sx = i if sy > j: sy = j if ex <= i: ex = i+1 if ey <= j: ey = j+1 return [sx,sy,ex,ey]
반응형'코딩테스트' 카테고리의 다른 글
5. 셋(집합) (0) 2024.03.20 4. 딕셔너리(해시맵) (0) 2024.03.20 2. 구현 (4) 2024.03.18 1. 문자열 다루기 (2) 2024.03.17 코딩테스트 문제 유형 별 정리 및 문제 모음 (0) 2024.03.17