본문 바로가기

binarysearch5

[LeetCode 풀이/python] 81. Search in Rotated Sorted Array II (medium) 문제 설명: 정수 배열 nums 는 오름차순 정렬되어 있다 (항상 구분되는 distinct 값들로만 구성된 것은 아님). 네가 작성한 함수를 통과하기 전, 배열 nums 는 알려지지 않은 피벗 인덱스 k (0 출력: false 제한 조건: 1 2021. 3. 3.
[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] 41. First Missing Positive (hard) 문제 설명: 정렬되지 않은 정수 배열 nums 가 주어졌을 때, 해당 배열에서 누락된 양의 정수 중 가장 작은 수를 찾으시오. (Given an unsorted integer array nums, find the smallest missing positive integer.) 예시 1) 입력: nums = [1,2,0] --> 출력: 3 예시 2) 입력: nums = [3,4,-1,1] --> 출력: 2 예시 3) 입력: nums = [7,8,9,11,12] --> 출력: 1 제한 조건: 0 2021. 2. 15.
[LeetCode 풀이/python] 34. Find First and Last Position of Element in Sorted Array (medium) 문제 설명: 오름차순 정렬된 정수 배열 nums 이 주어졌을 때, 배열 안에서 주어진 target 값이 등장하는 처음과 마지막 위치를 찾으시오. 만약 target 값이 배열 안에 존재하지 않으면, [-1, -1] 을 리턴하시오. + 추가: 시간 복잡도 O(log n) 의 알고리즘을 작성하시오 (Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. Follow up: Could you write an algorithm with O(log n) run.. 2021. 2. 14.
[LeetCode 풀이/python] 35. Search Insert Position (easy) 문제 설명: 구분되는 (중복이 없는) 정수 값들이 정렬된 배열 nums 과 타겟 값 target 이 주어졌을 때, target 이 배열 안에 존재하면 그 인덱스를 리턴하시오. 배열 안에 존재하지 않는 경우, 만약 정렬 순서에 맞게 타겟 값을 삽입한다면 들어가게 될 위치를 리턴하시오. (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.) 예시 1) 입력: nums = [1,3,5,6], target = 5 --> 출력: 2 예시 2) 입력: nu.. 2021. 2. 7.