Leetcode Problem Minimum Flips to Make a OR b Equal to c a | b 연산을 하여 c가 나오게 하기 위해 a와 b의 bit를 몇 개 뒤집어야 하는지 구하는 문제입니다. class Solution: def minFlips(self, a: int, b: int, c: int) -> int: ...
Can Make Arithmetic Progression From Sequence
Leetcode Problem Can Make Arithmetic Progression From Sequence 주어진 배열을 정렬했을 때 등차수열인지 판별하는 문제입니다. class Solution: def canMakeArithmeticProgression(self, arr: List[int]) -> bool: arr...
Check If It Is a Straight Line
Leetcode Problem Check If It Is a Straight Line 주어진 점들이 일직선을 이루는 지 판별하는 문제입니다. class Solution: def checkStraightLine(self, coordinates: List[List[int]]) -> bool: x, y = coordinates...
Range Addition II
Leetcode Problem Range Addition II ops 배열에서 주어진 범위만큼 숫자가 1씩 증가할 때, 가장 많이 증가한 수의 범위를 구하는 문제입니다. class Solution: def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int: retu...
Design Underground System
Leetcode Problem Design Underground System UndergroundSystem class에서 checkIn과 checkOut 함수가 주어졌을 때 두 함수를 이용해 getAverageTime 함수를 구하는 문제입니다. class UndergroundSystem: def __init__(self): ...
Detonate the Maximum Bombs
Leetcode Problem Detonate the Maximum Bombs bomb이 주어진 배열에서 하나의 폭탄이 터질 경우 최대 터질 수 있는 폭탄의 개수를 구하는 문제입니다. from collections import defaultdict class Graph: def __init__(self): self.graph = default...
Shortest Path in Binary Matrix
Leetcode Problem Shortest Path in Binary Matrix 주어진 2차원 배열에서 (0, 0)에서 (-1, -1)까지 갈 수 있는 최단 거리를 구하는 문제입니다. class Solution: def shortestPathBinaryMatrix(self, grid: List[List[int]]) -> int: ...
Design HashSet
Leetcode Problem Design HashSet hashset을 사용하여 add, remove, contains 함수를 구현하는 문제입니다. class MyHashSet: def __init__(self): self.hash = {} def add(self, key: int) -> None: ...
N-ary Tree Postorder Traversal
Leetcode Problem N-ary Tree Postorder Traversal tree가 주어졌을 때, postorder 수행 결과를 구하는 문제입니다. class Solution: def postorder(self, root: 'Node') -> List[int]: return sum([self.postorder...
N-ary Tree Preorder Traversal
Leetcode Problem N-ary Tree Preorder Traversal tree가 주어졌을 때, preorder 수행 결과를 구하는 문제입니다. class Solution: def preorder(self, root: 'Node') -> List[int]: return [root.val] + sum([self...