본문 바로가기

ProblemSolving45

[LeetCode 풀이/python] 166. Fraction to Recurring Decimal (medium) 문제 설명: 분수에서 각각 분자와 분모를 나타내는 두 개의 정수가 주어졌을 때, 해당 분수의 값을 문자열(string) 형태로 리턴하시오. 분수 값에 반복되는 부분이 있을 경우, 해당 부분을 괄호로 감싸시오. 복수의 답이 가능할 경우 그 중 어느 답을 리턴해도 상관 없으며, 주어지는 모든 입력에 대해 정답 문자열의 길이는 10^4 을 넘지 않음이 보장된다. (Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. I.. 2021. 3. 18.
[LeetCode 풀이/python] 154. Find Minimum in Rotated Sorted Array II (hard) 문제 설명: 크기 n 의 오름차순 정렬된 배열 nums 가 1 에서 n 사이의 횟수만큼 회전되어 있다. 예를 들어, 배열 nums = [0,1,4,4,5,6,7] 은 다음과 같이 될 수 있다: 4 번 회전할 경우 [4,5,6,7,0,1,4] 7 번 회전할 경우 [0,1,4,4,5,6,7] 배열 [a[0], a[1], a[2], ..., a[n-1]] 을 한 번 회전한 결과는 [a[n-1], a[0], a[1], a[2], ..., a[n-2]] 와 같다. 정렬되어 회전된 배열 nums 가 주어졌을 때, 해당 배열이 중복(duplicates) 을 포함할 경우, 해당 배열에서 가장 작은 원소를 찾아 리턴하시오. (Suppose an array of length n sorted in ascending orde.. 2021. 3. 18.
[LeetCode 풀이/python] 152. Maximum Product Subarray (medium) 문제 설명: 정수 배열 nums 가 주어졌을 때, 하나 이상의 원소가 존재하며 연속하는 부분 배열(subarray) 중 가장 큰 곱을 갖는 배열을 찾아 이 때의 곱셈 값을 리턴하시오. 정답은 32-비트 정수로 표현할 수 있음이 보장되며, 부분 배열은 해당 배열의 연속하는 부분집합이다. (Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. It is guaranteed that the answer will fit in a 32-bit integer. A subarray is a contiguous subsequenc.. 2021. 3. 18.
[LeetCode 풀이/python] 139. Word Break (medium) 문제 설명: 문자열 s 와 문자열 사전 wordDict 가 주어졌을 때, 사전에 포함된 하나 이상의 단어로 이루어지며 각 단어가 띄어쓰기로 구분되는 시퀀스로 s 가 분해될 수 있으면 true 를 리턴하시오. 참고로 사전에 포함된 각 단어는 분해 과정에서 여러 번 사용될 수 있다. (Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may be reused multiple times in the segmenta.. 2021. 3. 12.
[LeetCode 풀이/python] 135. Candy (hard) 문제 설명: 일렬로 줄 서있는 n 명의 어린이가 있다. 이들 각 어린이가 받은 점수는 정수 배열 ratings 에 저장되어 있다. 너는 다음과 같은 요구 조건을 만족하도록 이들 어린이에게 사탕을 주어야 한다: 각 어린이는 최소 하나의 사탕을 가진다 더 높은 점수를 받은 어린이는 이웃한 어린이보다 더 많은 사탕을 가진다 이들 어린이에게 사탕을 나눠주기 위해 필요한 사탕의 최소 개수를 리턴하시오. (There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these children subjected to the fo.. 2021. 3. 12.