[LeetCode] 262. Trips and Users
·
코딩테스트/MySQL
🔗 Problem Linkhttps://leetcode.com/problems/trips-and-users/description/❔Thinking2013-10-01와 2013-10-03 사이의 cancellation rate를 각 일자별로 계산한 테이블을 반환한다.cancellation rate = banned 되지 않은 user 가운데에 calleced 되지 않은 상태의 비율Input: Trips table:+----+-----------+-----------+---------+---------------------+------------+| id | client_id | driver_id | city_id | status | request_at |+----+----------..
[LeetCode] 1732. Find the Highest Altitude
·
코딩테스트/Python
🔗 Problem Linkhttps://leetcode.com/problems/find-the-highest-altitude/description/❔Thinking현재의 높이 0에서 주어지는 높이와의 차이를 순차적으로 계산하고(= net gain altitude) 업데이트한다.모든 net gain altitude 가운데에 가장 큰 값을 반환한다.💻Solutiondef largestAltitude(self, gain: List[int]) -> int: net_gain = [0] for h in gain: net_gain.append(net_gain[-1] + h) return max(net_gain)🗝️keypoint리스트 선언의 필요 없이, 두개의 변수를 통해 max 값..
[LeetCode] 185. Department Top Three Salaries
·
코딩테스트/MySQL
🔗 Problem Linkhttps://leetcode.com/problems/department-top-three-salaries/description/❔Thinking각 부서별 임금 상위 3개를 상위 임금자라 할 때, 상위 임금자의 부서와 이름, 임금을 반환한다.Input:Employee table:+----+-------+--------+--------------+| id | name | salary | departmentId |+----+-------+--------+--------------+| 1 | Joe | 85000 | 1 || 2 | Henry | 80000 | 2 || 3 | Sam | 60000 | 2 ..
[LeetCode] 1493. Longest Subarray of 1's After Deleting One Element
·
코딩테스트/Python
🔗 Problem Linkhttps://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/description/❔Thinking0과 1로 숫자 배열 nums가 주어질 때, 0 한 개를 제거하여 만들 수 있는 가장 긴 1 부분수열의 길이를 반환한다.[1,1,0,1] 이라면 111이므로 3 반환💻Solutiondef longestSubarray(self, nums: List[int]) -> int: delete_cnt = 1 left = 0 longest_len = 0 for right in range(len(nums)): if nums[right] == 0: delete_..
[LeetCode] 184. Department Highest Salary
·
코딩테스트/MySQL
🔗 Problem Linkhttps://leetcode.com/problems/department-highest-salary/description/❔ThinkingEmployee 테이블과 Department 테이블이 주어질 때, 각 부서별 최고 연봉을 받는 사람의 정보를 담은 테이블을 반환한다.Input: Employee table:+----+-------+--------+--------------+| id | name | salary | departmentId |+----+-------+--------+--------------+| 1 | Joe | 70000 | 1 || 2 | Jim | 90000 | 1 || 3 | Henry | 80000..
[LeetCode] 1004. Max Consecutive Ones III
·
코딩테스트/Python
🔗 Problem Linkhttps://leetcode.com/problems/max-consecutive-ones-iii/description/❔Thinking0과 1로 이루어진 숫자 배열이 주어질 때, k개의 0을 1로 바꾸어 만들 수 있는 1 부분 수열의 최대 길이를 반환한다.ex - 0 0 1 1 1 0 1, k=1 이라면 111 0 1에서 0을 1로 바꾸어 11111을 만들 수 있으므로 5 반환💻Solution1. left, right Two-Pointer를 활용한 풀이left와 right로 0을 1로 바꾼 횟수가 k를 넘지 않도록 window 구성만약 현재 0을 1로 바꾼 횟수가 k를 넘은 경우, left를 이동하여 cur_zero_cnt를 k보다 작게 유지한다.right-left+1로 w..