일상용41 [leetcode] 3-15회차 https://leetcode.com/problems/n-queens-ii/submissions/1668985767/?envType=study-plan-v2&envId=top-interview-150class Solution(object): def totalNQueens(self, n): """ :type n: int :rtype: int """ self.res = 0 self.dfs([-1]*n, 0) return self.res def dfs(self, nums, index): if index == len(nums): self.res += 1 retur.. 2025. 6. 19. [leetcode] 3-14회차 https://leetcode.com/problems/permutations/?envType=study-plan-v2&envId=top-interview-150class Solution(object): def permute(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ ans = [] q = collections.deque() for num in (nums): q.append(([num], 1)) while q: permu, cnt = q.popleft() .. 2025. 6. 18. [leetcode] 3-13회차 https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/?envType=study-plan-v2&envId=top-interview-150class Solution(object): def letterCombinations(self, digits): """ :type digits: str :rtype: List[str] """ letters = ["", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"] ans = [] if digits == "": .. 2025. 6. 16. [leetcode] 3-13회차 https://leetcode.com/problems/word-search-ii/description/?envType=study-plan-v2&envId=top-interview-150처음 접근했을 때는 board 를 trie 로 만들어서 접근했다.그렇게 접근했을 때의 문제는 공간복잡도가 너무 늘어난다는 점이다. 그리고 정답으로 인정되는 코드들 대부분이 시간 복잡도에서 걸렸다.아래는 그 중에서 10초 내에 결과를 출력하는 답이다. class Solution(object): def findWords(self, board, words): """ :type board: List[List[str]] :type words: List[str] :rtype: .. 2025. 6. 13. [leetcode] 3-13회차 https://leetcode.com/problems/implement-trie-prefix-tree/?envType=study-plan-v2&envId=top-interview-150 trie 문제다.문제는 내가 trie 자료구조가 기억이 안난다.기억을 살릴 겸 블로그를 살펴본다.https://velog.io/@kimdukbae/%EC%9E%90%EB%A3%8C%EA%B5%AC%EC%A1%B0-%ED%8A%B8%EB%9D%BC%EC%9D%B4-Trie [자료구조] 트라이 (Trie)트라이(Trie)는 문자열을 저장하고 효율적으로 탐색하기 위한 트리 형태의 자료구조이다.우리가 검색할 때 볼 수 있는 자동완성 기능, 사전 검색 등 문자열을 탐색하는데 특화되어있는 자료구조velog.io https://cod.. 2025. 6. 10. [leetcode] 3-12 회차 날이 많이 더워졌다. 그만큼 새들도 많이 보여서 좋다. 한국에 살아서 최고의 복지는 예쁜 원앙들을 쉽게 볼 수 있다는 점도 포함되어 있을 것이다. https://leetcode.com/problems/word-ladder/description/?envType=study-plan-v2&envId=top-interview-150class Solution(object): def ladderLength(self, beginWord, endWord, wordList): """ :type beginWord: str :type endWord: str :type wordList: List[str] :rtype: int """ .. 2025. 6. 9. [leetcode] 3-11회차 오늘은 선거날이다. 대부분의 공공기관 휴무일이다.그래서 도서관 갔다가 휴무일이라 슬펐지만, 날이 참 좋아서 이냥저냥 괜찮은 하루다. https://leetcode.com/problems/minimum-genetic-mutation/description/?envType=study-plan-v2&envId=top-interview-150 class Solution(object): def minMutation(self, startGene, endGene, bank): """ :type startGene: str :type endGene: str :type bank: List[str] :rtype: int """ s .. 2025. 6. 3. [leetcode] 3-10회차 책을 샀다. 행복하다. https://leetcode.com/problems/course-schedule-ii/?envType=study-plan-v2&envId=top-interview-150class Solution(object): def findOrder(self, numCourses, prerequisites): """ :type numCourses: int :type prerequisites: List[List[int]] :rtype: List[int] """ self.graph = collections.defaultdict(list) self.res = [] for pair in prere.. 2025. 6. 2. [leetcode] 3-9회차 https://leetcode.com/problems/evaluate-division/?envType=study-plan-v2&envId=top-interview-150class Solution(object): def calcEquation(self, equations, values, queries): """ :type equations: List[List[str]] :type values: List[float] :type queries: List[List[str]] :rtype: List[float] """ G = collections.defaultdict(dict) for (x, y), v in .. 2025. 6. 1. 이전 1 2 3 4 5 다음