♟️ 알고리즘 146

[Python][프로그래머스] 프로세스 / 스택, (Lv2)

🖇️ 링크 https://school.programmers.co.kr/learn/courses/30/lessons/42587🗒️ 파이썬 코드 풀이def solution(priorities, location): queue = [(i,p) for i,p in enumerate(priorities)] answer = 0 while True : cur = queue.pop(0) if any(cur[1]  시간 복잡도 O( N² ) 1. deque 라이브러리 없이 풀이한 코드이다. deque를 안써도 되기는 하지만 pop(0)의 시간복잡도는 O(N)pop()의 시각복잡도는 O(1) 지금은 pop(0)을 써도 큰 상관은 없어서 쓰지만, 문제 생길 경우 deqeu..

[MySQL][Leet Code] 197. Rising Temperature (Easy)

https://leetcode.com/problems/rising-temperature/description/?envType=study-plan-v2&envId=top-sql-50 🗒️SQL 코드 풀이 SELECT idFROM Weather W1 INNER JOIN ( SELECT DATE_ADD(recordDate, INTERVAL 1 DAY) recordDate2, temperature FROM Weather ) W2 ON W1.recordDate = W2.recordDate2WHERE W1.temperature - W2.temperature > 0 1. 문제에서 요구하는 것은 간단하다. 전날과 비교해서 기온이 떨어지는 id를 출력하는 것이다. 2. ..

[MySQL][Leet Code] 1581. Customer Who Visited but Did Not Make Any Transactions (Easy)

https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/description/?envType=study-plan-v2&envId=top-sql-50🗒️SQL 코드 풀이 SELECT customer_id, COUNT(*) count_no_trans FROM Visits v LEFT JOIN Transactions t ON v.visit_id = t.visit_idWHERE t.visit_id IS NULLGROUP BY customer_id 1. LEFT JOIN을 하고 , visit_id 컬럼이 2개가 나오는데, 그 중 Transactions의 컬럼의 visit_id 의 NULL 값을 조회한다. 2. 이후 ..

[MySQL][Leet Code] 1378. Replace Employee ID With The Unique Identifier (Easy)

https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/description/?envType=study-plan-v2&envId=top-sql-50https://leetcode.com/problems/article-views-i/?envType=study-plan-v2&envId=top-sql-50🗒️SQL 코드 풀이 1SELECT unique_id , nameFROM Employees e LEFT JOIN EmployeeUNI eu ON e.id = eu.id 1. 간단한 JOIN 문제로 먼저 가져올 테이블 Employee를 선택한다. 2. 이후 EmployeeUNI와 JOIN을 하는데, id를 기준으로 해준다.  📌..

[MySQL][Leet Code] 1148. Article Views I (Easy)

https://leetcode.com/problems/find-customer-referee/description/?envType=study-plan-v2&envId=top-sql-50https://leetcode.com/problems/article-views-i/?envType=study-plan-v2&envId=top-sql-50🗒️SQL 코드 풀이 1SELECT DISTINCT author_id AS id FROM ViewsWHERE author_id = viewer_idORDER BY id 1. 간단한 SQL 문제이다.  먼저 가져올 테이블 Views를 선택한다. 2. 이후 author_id와 viewer_id가 같은 조건을 걸어준다 . 3. 선택 할 컬럼은 author_id이로 Alias는 ..

[Python][백준] 1365. 꼬인 전깃줄 / LIS,이분탐색(G2)

목차🖇️ 링크 https://www.acmicpc.net/problem/1365🗒️ 파이썬 코드 풀이from bisect import bisect_leftN = int(input())lst = list(map(int,input().split()))lis = [0]for i in range(len(lst)): if lis[-1]  1. 문제를 보고  LIS (Longest Increasing Sequence) 문제임을 알아야한다.처음 풀면, 생각할 수 없을 것 같다... 그냥 문제를 몇번 풀고 익숙해져야 될듯 2. 문제의 조건은 전봇대의 개수 N(1 ≤ N ≤ 100,000) 이다.때문에 시간복잡도가 O(N^2) 이하여야 함이중 for 문이 안되기 떄문에, 이분탐색으로 접근3. 이제 조건에 맞게 l..

[MySQL][Leet Code] 584. Find Customer Referee (Easy)

https://leetcode.com/problems/find-customer-referee/description/?envType=study-plan-v2&envId=top-sql-50🗒️SQL 코드 풀이 1SELECT nameFROM CustomerWHERE referee_id != 2 OR referee_id IS NULL 1. 간단한 SQL 문제이다.  Customer 테이블에서 referee_id가 2가 아닌 값을 찾아냄  2. 주의점은 referee_id에 NULL 값이 있는데, 이거 같은 경우 값이 아니기 때문에 같은 연산자로 못 찾음  3. 때문에 IS NULL 과 같은 방법으로 찾는다.  🗒️SQL 코드 풀이 2SELECT nameFROM CustomerWHERE COALESCE(r..