ETC
-
[LeetCode / Kotlin] Remove Covered IntervalsETC 2024. 7. 12. 16:35
문제Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list.The interval [a, b) is covered by the interval [c, d) if and only if c Return the number of remaining intervals. Example 1:Input: intervals = [[1,4],[3,6],[2,8]]Output: 2Explanation: Interval [3,6] is covered by [2,8], therefore it is rem..
-
[LeetCode / Kotlin] Merge IntervalsETC 2024. 7. 12. 16:31
문제Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. Example 1:Input: intervals = [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6]. Example 2:Input: intervals = [[1,4],[4..
-
[LeetCode / Kotlin] Add BinaryETC 2024. 7. 12. 01:14
문제Given two binary strings a and b, return their sum as a binary string. Example 1:Input: a = "11", b = "1"Output: "100" Example 2:Input: a = "1010", b = "1011"Output: "10101" Constraints:1 a and b consist only of '0' or '1' characters.Each string does not contain leading zeros except for the zero itself. 나의 풀이1. 자리수가 안맞는것을 포맷팅한다.2. 뒤에서부터 비교하며 연산을 한다. ... 유틸을 잘 알았다면 아래처럼 1줄로 가능함.더보기더보기class Sol..
-
[LeetCode / Kotlin] Pascal's TriangleETC 2024. 7. 11. 20:12
문제Given an integer numRows, return the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: Example 1:Input: numRows = 5Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]] Example 2:Input: numRows = 1Output: [[1]] Constraints:1 나의 풀이1. 부모자식의 관계를 파악한다. 예를들어, (2,1) 의 경우 (1,0) + (1,1) 이다. 그러므로, ans[i][j] = ans[i-1][j-1] + ans..
-
[LeetCode / Kotlin] Spiral MatrixETC 2024. 7. 11. 18:48
문제Given an m x n matrix, return all elements of the matrix in spiral order. Example 1:Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]Output: [1,2,3,6,9,8,7,4,5] Example 2:Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]Output: [1,2,3,4,8,12,11,10,9,5,6,7] Constraints:m == matrix.lengthn == matrix[i].length1 -100 나의 풀이1. 각 방향 별, 움직임을 정의한다.2. 이미 탐색했던곳을 검증하기 위한 MARKING_NUMBER를 지정. (제약사항에서 나올 수 없는 숫자인..
-
[LeetCode / Kotlin] Search Insert PositionETC 2024. 7. 11. 17:03
문제Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Example 1:Input: nums = [1,3,5,6], target = 5Output: 2 Example 2:Input: nums = [1,3,5,6], target = 2Output: 1 Example 3: Input: nums = [1,3,5,6], target = 7O..
-
[LeetCode / Kotlin] Diagonal TraverseETC 2024. 7. 11. 12:53
문제 Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order. Example 1:Input: mat = [[1,2,3],[4,5,6],[7,8,9]]Output: [1,2,4,7,5,3,6,8,9] Example 2:Input: mat = [[1,2],[3,4]]Output: [1,2,3,4] Constrains:m == mat.lengthn == mat[i].length1 1 -105 나의 풀이각 이동방향의 좌표 변화를 정의하고, 충돌케이스를 정의하였다.class Solution { fun findDiagonalOrder(mat: Array): IntArray { ..