본문 바로가기

leetcode73

[LeetCode][Kotlin] 41. First Missing Positive 41. First Missing PositiveGiven an unsorted integer array nums. Return the smallest positive integer that is not present in nums. You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.정렬되지 않은 정수 배열 nums가 주어졌습니다. nums에 존재하지 않는 가장 작은 양의 정수를 반환합니다. O(n) 시간에 실행되고 O(1) 보조 공간을 사용하는 알고리즘을 구현해야 합니다. Example 1:Input: nums = [1,2,0]Output: 3Explanation: The numbers in the ra.. 2024. 10. 18.
[LeetCode][Kotlin] 665. Non-decreasing Array 665. Non-decreasing ArrayGiven an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element. We define an array is non-decreasing if nums[i] 0-based) such that (0 n개의 정수로 구성된 nums 배열이 주어지면, 최대 하나의 요소를 수정하여 감소하지 않는 배열이 될 수 있는지 확인하는 것이 작업입니다. nums[i]  Example 1:Input: nums = [4,2,3]Output: trueExplanation: You could modify the first 4 to 1.. 2024. 10. 18.
[LeetCode][Kotlin] 304. Range Sum Query 2D - Immutable 304. Range Sum Query 2D - ImmutableGiven a 2D matrix matrix, handle multiple queries of the following type:Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).Implement the NumMatrix class:NumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix.int sumRegion(int row1, int col1, .. 2024. 10. 18.
[LeetCode][Kotlin] 838. Push Dominoes 838. Push DominoesThere are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a ve.. 2024. 10. 18.
[LeetCode][Kotlin] 75. Sort Colors 75. Sort ColorsGiven an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. You must solve this problem without using the library's sort function.빨간색, 흰색 또는 파란색으로 색상이 지정된 n개의 개체가 포함.. 2024. 10. 18.
[LeetCode][Kotlin] 36. Valid Sudoku 36. Valid SudokuDetermine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column must contain the digits 1-9 without repetition.Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.Note:A Sudoku board (partially filled) could be valid b.. 2024. 10. 18.
[LeetCode][Kotlin] String Encode and Decode String Encode and DecodeDesign an algorithm to encode a list of strings to a single string. The encoded string is then decoded back to the original list of strings. Please implement encode and decode문자열 목록을 단일 문자열로 인코딩하는 알고리즘을 설계합니다. 인코딩된 문자열은 원래 문자열 목록으로 다시 디코딩됩니다. encode와 decode를 구현하세요. Example 1:Input: ["neet","code","love","you"]Output:["neet","code","love","you"] Example 2:Input: ["we","say.. 2024. 10. 18.