본문 바로가기

ProblemSolving45

[LeetCode 풀이/python] 127. Word Ladder (hard) 문제 설명: 사전 wordList 를 이용하여 단어 beginWord 를 endWord 로 변환하는 시퀀스는 다음과 같은 일련의 단어(단어 시퀀스) 를 가리킨다: 시퀀스의 첫번째 단어는 beginWord 이다 시퀀스의 마지막 단어는 endWord 이다 시퀀스에서 인접한 각 단어 쌍은 서로 오직 한 글자씩만 다르다 시퀀스의 모든 단어는 wordList 에 존재한다 두 단어 beginWord 와 endWord, 그리고 사전 wordList 가 주어졌을 때, beginWord 에서 endWord 로의 가장 짧은 변환 시퀀스의 길이 (단어의 개수) 를 리턴하고, 만약 그러한 시퀀스가 존재하지 않는 경우 0 을 리턴하시오. (A transformation sequence from word beginWord to .. 2021. 3. 12.
[LeetCode 풀이/python] 113. Path Sum II (medium) 문제 설명: 이진트리 root 와 정수 targetSum 이 주어졌을 때, 루트에서 단말 노드까지의 경로에 있는 모든 수의 합이 targetSum 과 같아지는 경로를 모두 리턴하시오. 단말 노드는 자식 노드를 갖지 않는 노드를 가리킴. (Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where each path's sum equals targetSum. A leaf is a node with no children.) 예시 1) 입력: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22 --> 출력: [[5,4,11,2],[5,8,4,5].. 2021. 3. 10.
[LeetCode 풀이/python] 101. Symmetric Tree (easy) 문제 설명: 이진트리 root 가 주어졌을 때, 해당 트리가 자기 자신의 거울인지 (i.e. 중심을 기준으로 대칭인지) 확인하시오. (Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).) 예시 1) 입력: root = [1, 2, 2, 3, 4, 4, 3] --> 출력: true 예시 2) 입력: root = [1, 2, 2, null, 3, null, 3] --> 출력: false 제한 조건: 트리의 노드 개수는 [1, 1000] 의 범위 내에 있음 -100 bool: if not root: return False else: return self.check_sy.. 2021. 3. 10.
[LeetCode 풀이/python] 85. Maximal Rectangle (hard) 문제 설명: 0 과 1 로만 채워진 rows x cols 형태의 행렬 matrix 가 주어졌을 때, 1 만 포함하는 가장 큰 직사각형을 찾고 그 넓이를 리턴하시오. (Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.) 예시 1) 입력: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] --> 출력: 6 설명: 최대 크기의 직사각형은 위의 그림에 표시되어 있음 예시 2) 입력: matrix = [] --> .. 2021. 3. 7.
[LeetCode 풀이/python] 84. Largest Rectangle in Histogram (hard) 문제 설명: 정수 배열 heights 는 히스토그램 막대의 높이를 나타내며, 각 막대의 너비는 1 이다. 이 때, 히스토그램에서 가장 큰 직사각형의 넓이를 리턴하시오. (Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.) 예시 1) 입력: heights = [2,1,5,6,2,3] --> 출력: 10 설명: 가장 큰 직사각형은 붉게 나타난 영역으로, 각 막대의 너비가 1 이므로 총 넓이 10 을 갖는다. 예시 2) 입력: heights = [2,4] --> .. 2021. 3. 7.