세조목

TIL(Today I Learned) 75일차(24.02.22) 본문

데이터 분석 공부/TIL(Today I Learned)

TIL(Today I Learned) 75일차(24.02.22)

세조목 2024. 2. 22. 21:54

SQL & PYTHON 예제

SQL

180. Consecutive Numbers

2024.02.22 - [데이터 분석 공부/SQL] - SQL 예제(Consecutive Numbers)(Lead 함수)

 

SQL 예제(Consecutive Numbers)(Lead 함수)

LeetCode 180. Consecutive Numbers https://leetcode.com/problems/consecutive-numbers/description/ WITH CON AS( SELECT NUM, LEAD(NUM, 1) OVER() NEXT_ORDER, LEAD(NUM, 2) OVER() NEXT_ORDER2 FROM LOGS ) SELECT DISTINCT NUM CONSECUTIVENUMS FROM CON WHERE (NUM=NE

eyeoftheworld1209.tistory.com

https://leetcode.com/problems/consecutive-numbers/description/

WITH CON AS(
    SELECT NUM,
        LEAD(NUM, 1) OVER() NEXT_ORDER,
        LEAD(NUM, 2) OVER() NEXT_ORDER2
    FROM LOGS
)
SELECT DISTINCT NUM CONSECUTIVENUMS
FROM CON
WHERE (NUM=NEXT_ORDER) AND (NUM=NEXT_ORDER2)

 

PYTHON

최대공약수와 최소공배수

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

def solution(n, m):
    answer = []
    div1 = []
    div2 = []
    co_div = []
    mul1 = []
    mul2 = []
    co_mul = []   
    
    for i in range(1, n+1):
        if n % i == 0:
            div1.append(i)
    for j in range(1, m+1):
        if m % j == 0:
            div2.append(j)
    for a in div1:
        for b in div2:
            if a == b:
                co_div.append(a)
    max_div = max(co_div)
    
    for i in range(1, m+1):
        c = i * n
        mul1.append(c)
        d = i * m
        mul2.append(d)
    for i in mul1:
        for j in mul2:
            if i == j:
                co_mul.append(i)
    min_mul = min(co_mul)
    
    answer.append(max_div)
    answer.append(min_mul)
    
    return answer