본문 바로가기

알고리즘 문제풀이/leetcode142

[leetcode 332] Reconstruct Itinerary 내가 이 문제를 푼 적이 있었다니 전혀 기억이.. 문제 난이도는 hard이다. 다시 풀어도 또 못 풀꺼 같다. https://leetcode.com/problems/reconstruct-itinerary/description/ Reconstruct Itinerary - LeetCode Can you solve this real interview question? Reconstruct Itinerary - You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order.. 2023. 4. 15.
[leetcode 378] Kth Smallest Element in a Sorted Matrix leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/ 이진탐색이지만 매우 어려웠다. 문제: row별 col별 오름차순 된 이차원 배열에서 오름차순으로 k번째 원소 찾기 접근: 1. 이진 탐색 사용: left는 matrix[0][0] (최솟값) right는 matrix[n-1][n-1] (최댓값) 2. mid 구하기 동일 3. 기준점: mid를 기준으로 mid보다 작거나 같은 값의 개수를 센다. 그 개수가 k보다 작다면 left = mid+1로, k보다 크거나 같다면 right = mid로 이동시킨다. 3-1. mid보다 작거나 같은 값 개수 세기 row는 0부터 col는 n-1부터 돌면서 matrix[row][col] 2021. 2. 11.
[leetcode 103] Binary Tree Zigzag Level Order Traversal Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree [3,9,20,null,null,15,7], return its zigzag level order traversal as: 문제 풀이: 기존 level 순회에서 레벨에 따라 reverse가 추가된다. /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *l.. 2020. 12. 3.
[leetcode 268] Missing Number Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity? Example 1: Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing numb.. 2020. 12. 3.