Home
icyou
Cancel

Find Mode in Binary Search Tree

Leetcode Problem Find Mode in Binary Search Tree 이진 탐색 트리에서 가장 빈번하게 나오는 수들을 구하는 문제입니다. 가장 많이 나오는 수가 여러개일 경우 전부 구해야 합니다. from collections import Counter class Solution: def traverse(self, root...

Construct the Rectangle

Leetcode Problem Construct the Rectangle 키보드의 한 줄로만 단어를 구성할 수 있는 경우만 구하는 문제입니다. class Solution: def findWords(self, words: List[str]) -> List[str]: d = { 'q': 1,'w': 1, 'e': 1, 'r'...

Next Greater Element I

Leetcode Problem Next Greater Element I nums2 배열과 nums2 배열의 부분집합인 nums1이 주어졌을 때, nums1을 순회하면서 nums1 원소를 nums2에서 봤을 때, 다음으로 큰 수를 찾는 문제입니다. 만약 다음으로 큰 수가 없을 경우 그 자리에 -1을 넣습니다. class Solution: de...

Teemo Attacking

Leetcode Problem Teemo Attacking 티모가 애쉬를 timeSeries의 배열 때마다 공격했을 때, 애쉬가 받는 총 피해를 구하는 문제입니다. 단 독 데미지는 중첩이 되지 않습니다. class Solution: def findPoisonedDuration(self, timeSeries: List[int], duratio...

Construct the Rectangle

Leetcode Problem Construct the Rectangle 사각형의 넓이가 주어졌을 때, 사각형의 길이와 너비의 차이가 최소가 되도록 하는 길이와 너비를 구하는 문제입니다. 단, 길이가 너비보다 크거나 같아야 합니다. class Solution: def constructRectangle(self, area: int) ->...

Max Consecutive Ones

Leetcode Problem Max Consecutive Ones 주어진 nums 배열에서 1이 연속하여 나온 길이의 최댓값을 구하는 문제입니다. class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: cnt, m = 0, 0 f...

License Key Formatting

Leetcode Problem License Key Formatting 주어진 문자열 s를 k 길이마다 -로 연결하는 새로운 형태의 문자열을 만드는 문제입니다. 단, 첫번째 길이만 k 이하의 길이가 될 수 있습니다. class Solution: def licenseKeyFormatting(self, s: str, k: int) -> s...

Number Complement

Leetcode Problem Number Complement 주어진 수, num의 이진수 표현에서 0을 모두 1로 바꾸고 1을 모두 0으로 바꾼 수를 구하는 문제입니다. class Solution: def findComplement(self, num: int) -> int: n = "" for s in b...

Island Perimeter

Leetcode Problem Island Perimeter 2차원 배열 grid에서 1은 땅이고 0은 물이라고 하면, 땅의 테두리의 길이를 구하는 문제입니다. class Solution: def islandPerimeter(self, grid: List[List[int]]) -> int: cnt = 0 f...

Hamming Distance

Leetcode Problem Hamming Distance 주어진 두 정수의 이진수에서 서로 다른 bit의 개수를 구하는 문제입니다. class Solution: def hammingDistance(self, x: int, y: int) -> int: cnt = 0 for i in range(31): ...