본문 바로가기

ProblemSolving45

[LeetCode 풀이/python] 81. Search in Rotated Sorted Array II (medium) 문제 설명: 정수 배열 nums 는 오름차순 정렬되어 있다 (항상 구분되는 distinct 값들로만 구성된 것은 아님). 네가 작성한 함수를 통과하기 전, 배열 nums 는 알려지지 않은 피벗 인덱스 k (0 출력: false 제한 조건: 1 2021. 3. 3.
[LeetCode 풀이/python] 79. Word Search (medium) 문제 설명: m x n 형태의 격자판 board 와 단어 word 가 주어졌을 때, 해당 격자판에 단어 word 가 존재하는지를 찾으시오. 단어 word 는 연속적으로 인접한 셀의 문자들로 구성될 수 있으며, 이 때 '인접한' 셀들은 수평 혹은 수직 방향으로 이웃한 것들이다. 동일한 문자 셀은 한 번을 초과하여 사용될 수 없다. (Given an m x n board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are horizontally or vertically neighboring. Th.. 2021. 3. 3.
[LeetCode 풀이/python] 75. Sort Colors (medium) 문제 설명: 빨강, 하양, 파랑으로 색칠된 n 개의 객체를 포함하는 배열 nums 가 주어졌을 때, 동일한 색상의 객체끼리 서로 인접하도록 이들을 제자리 방식으로 (in-place) 정렬하시오. 정렬 순서는 빨강, 하양, 파랑 순서이며, 각 색상은 정수 0, 1, 2 로 표현되어 있다. (Given 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 .. 2021. 2. 24.
[LeetCode 풀이/python] 74. Search a 2D Matrix (medium) 문제 설명: m x n 행렬에서 하나의 값 value 을 찾는 효율적인 알고리즘을 작성하시오. 해당 행렬은 다음과 같은 특성을 지니고 있다: 각 행의 정수들은 왼쪽에서 오른쪽으로 (오름차순) 정렬되어 있다 각 행의 첫번째 정수는 이전 행의 마지막 정수보다 크다 (Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row.. 2021. 2. 23.
[LeetCode 풀이/python] 73. Set Matrix Zeros (medium) 문제 설명: m x n 형태의 행렬이 하나 주어졌을 때, 한 요소의 값이 0 이면 해당 요소가 속한 행과 열을 전체를 0 으로 설정하시오. 이를 제자리 방식으로 (in-place) 수행하시오. + 추가: O(mn) 공간을 사용하는 가장 단순한 해결책은 좋지 않은 방법일 것이다. 이를 단순히 개선하여 O(m+n) 공간을 사용하는 경우에도 여전히 최적의 해결책은 아니다. 상수 공간(constant space) 해결책을 고안해낼 수 있는가? (Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place. Follow up: A straight forward solution using O(m*n) spac.. 2021. 2. 23.