Home
icyou
Cancel

Isomorphic Strings

Leetcode Problem Isomorphic Strings s, t 두 문자열이 주어졌을 때, s 문자열의 문자들과 t 문자열의 문자들이 서로 일대일 대응인지를 구하는 문제입니다. class Solution: def isIsomorphic(self, s: str, t: str) -> bool: d = {} ...

Invert Binary Tree

Leetcode Problem Invert Binary Tree 주어진 binary tree를 좌우반전시키는 문제입니다. class Solution: def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: if root: node ...

Largest Odd Number in String

Leetcode Problem Largest Odd Number in String 주어진 문자열에서 가장 큰 홀수인 부분 문자열을 구하는 문제입니다. class Solution: def largestOddNumber(self, num: str) -> str: while num: if int(num[-...

Valid Sudoku

Leetcode Problem Valid Sudoku 유효한 스도쿠를 판별하는 문제입니다. class Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: for i in range(9): arr = [] if n...

Remove Linked List Elements

Leetcode Problem Remove Linked List Elements Linked List에서 주어진 수를 제거한 Linked List를 반환하는 문제입니다. class Solution: def removeElements(self, head: Optional[ListNode], val: int) -> Optional[List...

Sort Colors

Leetcode Problem Sort Colors nums 배열을 in-place 정렬을 하는 문제입니다. class Solution: def sortColors(self, nums: List[int]) -> None: tmp = 0 for i in range(len(nums) - 1): ...

Ugly Number

Leetcode Problem Ugly Number 주어진 수가, 2 또는 3 또는 5 이외를 인수로 가지지 않는 Ugly Number인지를 판별하는 문제입니다. class Solution: def isUgly(self, n: int) -> bool: if n == 1: return True ...

Add Digits

Leetcode Problem Add Digits 각 자릿 수를 더했을 때 한자릿 수가 될 경우까지 각 자릿 수를 더하여 그 숫자를 구하는 문제입니다. class Solution: def addDigits(self, num: int) -> int: num = sum(int(x) for x in str(num)) ...

Happy Number

Leetcode Problem Happy Number 주어진 수가 happy number인지를 판단하는 문제입니다. Happy number는 반복적으로 각 자릿수의 제곱을 더했을 때 마지막에 1이 나오는 수입니다. class Solution: def isHappy(self, n: int) -> bool: arr, num ...

Binary Tree Paths

Leetcode Problem Binary Tree Paths 주어진 Binary Tree에서 각 leaf node까지의 경로를 구하는 문제입니다. class Solution: def binaryTreePaths(self, root): if not root: return [] res = []...