leetcode30 leet code - 17. Letter Combinations of a Phone Number (medium, back track) 17. Letter Combinations of a Phone Number Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1:Input: digits = "23"Output: ["ad","ae","af","bd","be","bf","c.. 2025. 4. 14. leet code - 876. Middle of the Linked List 1. 배열을 이용한 풀이. 문제의 특징 파악: 연결 리스트는 배열과 달리 무작위 접근이 불가능하다. 이는 연결 리스트의 특정 인덱스에 직접 접근하려면 시작 노드부터 순차적으로 접근해야 한다는 것을 의미한다. 배열의 특징 활용: 배열은 무작위 접근이 가능하므로, 연결 리스트의 각 노드를 배열에 순서대로 저장하면 해당 배열의 중간 인덱스를 통해 중간 노드에 빠르게 접근할 수 있다. 간단한 구현: 연결 리스트를 순회하면서 배열에 노드를 저장하는 방법은 코드 구현이 간단하다. # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next cl.. 2023. 8. 13. leet code 57 - Insert Interval 구간에 삽입하는 문제 class Solution: def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]: res = [] for i in range(len(intervals)): if newInterval[1] intervals[i][1]: res.append(intervals[i]) else: newInterval = [min(newInterval[0], intervals[i][0]), max(newInterval[1], intervals.. 2023. 5. 29. Leet code 36 - Valid Sudoku board가 주어지면, 그 board가 valid한지 판단하는 문제이다. 특정영역에 한정해서 순회하면 되기 떄문에 문제풀이에 있어 굳이 시간 복잡도에 대한 큰 고려는 하지 않아도 된다. 나의 풀이 class Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: # 먼저 한줄씩 찾는다. 중복되면 바로 invalid 해쉬 이용. check = {} # 가로 검사. for r in board: for c in range(9): if r[c] in check and r[c] != ".": return False check[r[c]] = 0 check = {} # 세로 검사. for c in range(9): check = {} for r in r.. 2023. 5. 18. 이전 1 2 3 4 5 6 ··· 8 다음