알고리즘
-
[프로그래머스 level.1] 06.19알고리즘 2023. 6. 19. 11:50
최소직사각형 더보기 https://school.programmers.co.kr/learn/courses/30/lessons/86491?language=javascript 내가 쓴 코드 function solution(sizes) { let width = []; let height = []; for(let i = 0; i < sizes.length; i++) { const max = Math.max(sizes[i][0], sizes[i][1]); const min = Math.min(sizes[i][0], sizes[i][1]); width.push(max); height.push(min) } const answer = Math.max(...width) * Math.max(...height) return ..
-
알고리즘 Day-1알고리즘 2023. 6. 16. 19:27
알고리즘을 풀면서 헷갈리는 개념에 대해서 다시 한번 적어 보자! 문자열을 반복하는 방법 : string.repeat(count) 아래 예제를 통해서 반복되는 개념을 다시 한번 상기해보자 https://programmers.co.kr/learn/courses/30/lessons/12969 슬라이싱 : slice() 두 정수 사이의 합 : Math.min() Math.max() Math.abs() 양 끝의 합 * (수의차 + 1) / 2 이렇게 계산하는 방식이 너무 수학적 계산이라서 생각도 못했음 ㄷ.. Number()를 써서 반환하는 값 : 숫자가 아닐 시에는(문자) NaN이 출력 프로그래머스에서는 null로 표시가 되어있어서 NaN이라는 것 찾는데 좀 고생 했음 filter를 통해서 차집합 교집합 이런거..
-
알고리즘 & 자료구조 스터디(10조) 8일차알고리즘 2023. 5. 30. 19:28
Q. 1003 피보나치 수 t = int(input()) for _ in range(t): zeroCount = [1, 0, 1] oneCount = [0, 1, 1] n = int(input()) for j in range(3, n + 1): oneCount.append(oneCount[j-1] + oneCount[j-2]) zeroCount.append(zeroCount[j-1] + zeroCount[j-2]) print(zeroCount[n], oneCount[n]) Q. 2609 공약수와 최소공배수 import math n,m = map(int, input().split()) print(math.gcd(n, m)) print(math.lcm(n, m)) Q. 9461 파도반 수 import sys..
-
알고리즘 & 자료구조 스터디(10조) 7일차알고리즘 2023. 5. 29. 20:36
Q. 2231 분해 num = int(input()) result = 0 for i in range(num): list_1 = list(map(int, str(i))) # [1, 9, 8] sum_num = sum(list_1) # 18 if num == i + sum_num: # i = 198 # num = 216 이랑 198 + 18 이 같으면 result 에 저장 하고 반복문 종료 result = i break print(result) Q. 2798 블랙 n,m = map(int,input().split()) data = list(map(int,input().split())) data.sort() munyeol = [] for i in data: for j in data: if i == j: con..