본문 바로가기

리트코드3

[Leetcode 1052번 문제] 1052. Grumpy Bookstore Owner 문제 상황There is a bookstore owner that has a store open for n minutes. Every minute, some number of customers enter the store. You are given an integer array customers of length n where customers[i] is the number of the customer that enters the store at the start of the ith minute and all those customers leave after the end of that minute.On some minutes, the bookstore owner is grumpy. You are giv.. 2024. 6. 21.
[Leetcode 330번 문제] 330. Patching Array 문제 상황Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.Return the minimum number of patches required.nums의 정렬 배열이 있고 n이라는 정수를 추가할 거임, 요소를 add/patch 한다, 1부터 n까지의 모든 수를 배열안의 수로 제작할 수 있게 되는 최소의 변형 수를 구하는 문제입력1 1 nums is sorted in ascending order.1 출력배열의 조합으로 [1.. 2024. 6. 17.
[Leetcode 881번 문제] 881. Boats to Save People 문제 설명사람 배열이라는게 존재함. 모든 사람들을 보트에 태워야한다. 보트에는 최대 2명이 탈 수 있고 그 두명의 무게의 합은 최대 중량 limit을 초과할 수 없다. 보트가 무한할때 이 인원들을 태울 수 있는 보트의 최소 숫자를 구해라.입력1이상 5만 이하의 사람배열각 사람의 무게는 limit과 3만보다 작고 1보다 큰 정수이다출력정수, 보트의 최소 개수과정보트를 태운다.배열이 나에게 아주 호의적인 상황이라면 (모든 탑승자의 크기가 limit / 2) 답은 뭐 나누기 2의 몫과 같음. 이 문제는 그렇지않음 보트의 수는 무한하다는것도 특징이다.그럼 이상적인상황을 만드는 방법을 구해야했다. 각 보트에 탈 수 있는 인원은 2명이 최대니까정렬해놓고 투포인터로 최소 무게 인원과 최대 무게 인원을 더해보는 방식을.. 2024. 5. 4.