본문 바로가기

ProblemSolving45

[LeetCode 풀이/python] 57. Insert Interval (medium) 문제 설명: 겹치지 않는 구간(interval) 집합 intervals 가 주어졌을 때, 해당 집합에 새로운 구간을 삽입하시오 (필요하다면 병합도 수행). 각 구간들은 시작 시간을 기준으로 정렬되어 초기화 되어 있다. (Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times.) 예시 1) 입력: intervals = [[1,3],[6,9]], newInterval = [2,5] --> 출력: [[1,5],[6,9]] 예시.. 2021. 2. 19.
[LeetCode 풀이/python] 55. Jump Game (medium) 문제 설명: 0 이상의 정수 배열 nums 가 주어지고, 초기 위치는 해당 배열의 첫번째 인덱스로 설정되어 있다. 배열의 각 요소가 해당 위치에서 가능한 최대 점프 길이를 나타낸다고 할 때, 가장 마지막 인덱스에 도달할 수 있는지를 확인하시오. (Given an array of non-negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index.) 예시 1) 입력: nums = [2,.. 2021. 2. 19.
[LeetCode 풀이/python] 54. Spiral Matrix (medium) 문제 설명: m x n 행렬이 주어졌을 때, 해당 행렬의 모든 요소를 나선형 순서(spiral order) 로 리턴하시오. (Given an m x n matrix, return all elements of the matrix in spiral order.) 예시 1) 입력: matrix = [[1,2,3],[4,5,6],[7,8,9]] --> 출력: [1,2,3,6,9,8,7,4,5] 예시 2) 입력: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] --> 출력: [1,2,3,4,8,12,11,10,9,5,6,7] 제한 조건: m == matrix.length n == matrix[i].length 1 k) and (j == k): if (i != k+1): i -= 1 .. 2021. 2. 19.
[LeetCode 풀이/python] 53. Maximum Subarray (easy) 문제 설명: 정수 배열 nums 가 주어졌을 때, 연속된 부분 배열(적어도 하나의 숫자를 포함하는) 중 가장 큰 합을 만들어내는 것을 찾고 그 합을 리턴하시오. (Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.) 예시 1) 입력: nums = [-2,1,-3,4,-1,2,1,-5,4] --> 출력: 6 설명: subarray [4,-1,2,1] 일 때 가장 큰 합 6을 만들 수 있다 예시 2) 입력: nums = [1] --> 출력: 1 예시 3) 입력: nums = [0] --> 출력: 0 예시 4) 입력: .. 2021. 2. 19.
[LeetCode 풀이/python] 50. Pow(x, n) (medium) 문제 설명: x 의 n 제곱 (i.e. x^n) 을 계산하는 함수 pow(x, n) 을 구현하시오. (Implement pow(x, n), which calculates x raised to the power n (i.e. x^n).) 예시 1) 입력: x = 2.00000, n = 10 --> 출력: 1024.0000 예시 2) 입력: x = 2.10000, n = 3 --> 출력: 9.26100 예시 3) 입력: x = 2.00000, n = -2 --> 출력: 0.25000 제한 조건: -100.0 < x < 100.0 -2^31 2021. 2. 16.