Home
icyou
Cancel

Diameter of Binary Tree

Leetcode Problem Diameter of Binary Tree 주어진 Binary Tree에서 왼쪽 끝 노드부터 오른쪽 끝 노드까지의 최대 길이를 구하는 문제입니다. class Solution: def __init__(self, maxi = 0): self.maxi = maxi def dfs(self, no...

Reverse String II

Leetcode Problem Reverse String II 문자열 s와 숫자 k가 주어졌을 때, k번씩 건너뛰면서 첫번째 문자열은 뒤집고 다음 문자열은 뒤집지 않는 방식으로 끝까지 구한 문자열을 구하는 문제입니다. class Solution: def reverseStr(self, s: str, k: int) -> str: ...

Minimum Absolute Difference in BST

Leetcode Problem Minimum Absolute Difference in BST 이진 탐색 트리(Binary Search Tree)에서 노드끼리의 최소 차이를 구하는 문제입니다. class Solution: def getMinimumDifference(self, root: Optional[TreeNode]) -> int: ...

Longest Uncommon Subsequence I

Leetcode Problem Longest Uncommon Subsequence I a와 b 문자열이 주어졌을 때, 두 문자열이 서로 일치하지 않는 최대 길이를 구하는 문제입니다. class Solution: def findLUSlength(self, a: str, b: str) -> int: return -1 if a...

Shell Grammar

Shell Grammar Shell Script Linux shell이나 command line interpreter에서 구동되도록 작성된 언어입니다. 변수 변수 사용 #!/bin/bash name="icyou" # 변수 선언 및 대입 pass=123123 # 따옴표로 감싸든 말든 문자열로 저장됩니다 echo $name # echo...

Detect Capital

Leetcode Problem Detect Capital 주어진 단어가 다음과 같은 조건을 만족하는지를 판별하는 문제입니다. 모든 문자가 대문자 모든 문자가 소문자 첫번째 문자만 대문자 class Solution: def detectCapitalUse(self, word: str) -> bool: if le...

Fibonacci Number

Leetcode Problem Fibonacci Number n번째 Fibonacci 수를 구하는 문제입니다. class Solution: def fib(self, n: int) -> int: return n if n < 2 else self.fib(n - 1) + self.fib(n - 2) 재귀로 간단하게 풀 ...

Perfect Number

Leetcode Problem Perfect Number 자기 자신을 제외한 모든 약수의 합이 자신과 같아지는 Perfect Number인지를 판별하는 문제입니다. class Solution: def checkPerfectNumber(self, num: int) -> bool: n = 1 for i in r...

Relative Ranks

Leetcode Problem Relative Ranks score 배열에서 각 점수의 등수를 구하는 문제입니다. class Solution: def findRelativeRanks(self, score: List[int]) -> List[str]: d, arr = {}, sorted(score, reverse=True)...

Base 7

Leetcode Problem Base 7 주어진 수 num을 7진수로 바꾸는 문제입니다. class Solution: def convertToBase7(self, num: int) -> str: n, sign = "", -1 if num < 0 else 1 num *= sign whil...