전체 글93 [LeetCode] 1006. Clumsy Factorial I. DescriptionII. Codeclass Solution: def clumsy(self, n: int) -> int: result = 0 add_or_sub = 1 for i in range(n, -1, -4): if i == 3: return (result + add_or_sub * 6) if i == 2: return (result + add_or_sub * 2) if i == 1: return (result + add_or_sub * 1) if i == 0: ret.. 2025. 1. 26. [LeetCode] 1003. Check If Word Is Valid After Substitutions I. DescriptionII. Codeclass Solution: def isValid(self, s: str) -> bool: if 'abc' in s: return self.isValid(s.replace('abc', '')) if s == '': return True return False같은 방식을 계속 반복해야 하므로 재귀함수를 사용했다. 2025. 1. 26. [LeetCode] 1441. Build an Array with Stack Operations I. DescriptionII. Codeclass Solution: def buildArray(self, target: List[int], n: int) -> List[str]: # 초기화 output_list = [] checked = 1 for i in range(1, n+1): if i in target: while checked != i: output_list.append("Push") output_list.append("Pop") checked += 1 .. 2025. 1. 26. [LeetCode] 36. Valid Sudoku I. DescriptionII. Codeclass Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: # 가로 중복 체크 for row in board: for i in row: if i != '.' and row.count(i) > 1: return False # 세로 중복 체크 for i in range(9): col = [row[i] for row in board] for j in col: if j != '.' and col.coun.. 2025. 1. 25. [LeetCode] 17. Letter Combinations of a Phone Number I. DescriptionII. Codeclass Solution: def letterCombinations(self, digits: str) -> List[str]: dict = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz'} result = [] for digit in digits: if not result: result = [i for i in dict[digit]] else: temp = result.copy() .. 2025. 1. 25. [LeetCode] 12. Integer to Roman I. DescriptionII. Codeclass Solution: def intToRoman(self, num: int) -> str: res = 'M' * (num // 1000) num %= 1000 val = num // 100 if val == 9: res += 'CM' elif val == 4: res += 'CD' else: res += 'D' * (val // 5) + 'C' * (val % 5) num %= 100 val = num // 10 if val == 9: .. 2025. 1. 25. [LeetCode] 1930. Unique Length-3 Palindromic Subsequences I. DescriptionII. Codeclass Solution: def countPalindromicSubsequence(self, s: str) -> int: # 변수 초기화 result = 0 for char in set(s): # char가 문자열에서 등장하는 처음과 마지막 인덱스 찾기 first = s.find(char) last = s.rfind(char) if last - first > 1: # 두 char 사이에 문자가 존재할 경우 unique_middle = set(s[first+1:last]) re.. 2025. 1. 25. [LeetCode] 2487. Remove Nodes From Linked List I. Description문제 링크: https://leetcode.com/problems/remove-nodes-from-linked-list/description/?envType=problem-list-v2&envId=stackII. Codei)# # Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclass Solution: def removeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]: stack = [] .. 2025. 1. 24. 이전 1 2 3 4 5 ··· 12 다음