[NeetCode/Python] Depth of Binary Tree
·
카테고리 없음
문제: https://neetcode.io/problems/depth-of-binary-tree NeetCode neetcode.io [내 풀이]# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightresult = 0class Solution: def maxDepth(self, root: Optional[TreeNode]) -> int: global result # 뭐지.. 연속으로 test case 처리하면서 ..
[LeetCode/Python] 383. Ransome Note
·
카테고리 없음
문제 링크: https://leetcode.com/problems/ransom-note/description/?envType=study-plan-v2&envId=top-interview-150 [풀이 코드]class Solution: def canConstruct(self, ransomNote: str, magazine: str) -> bool: # letter -> int book = {} for letter in magazine: if letter in book: book[letter] += 1 else: book[letter] = 1 fo..
[Go] pprof로 메모리 누수 찾아내기
·
Error Handling
보호되어 있는 글입니다.
[MongoDB] Skip 쿼리를 이용한 pagination 처리 시 주의할 점
·
Computer Science/Database
DB팀과 대화를 하면서 알게된, mongoDB에서 대용량 데이터 pagnination 처리(페이징 처리)를 할 때 주의할 점에 대해서 정리한다. mongo 쿼리로 페이지네이션 처리를 하는 가장 간단한 방법은 아마 아래와 같을 것입니다.1. 전체 데이터 개수를 구해서, 원하는 사이즈로 나눠서 순회를 돌린다.2. 쿼리는 sort, skip, limit 순서대로 사용한다. mongo에 대용량 데이터를 읽거나 쓸 때 모두 필요한 방법입니다.아무래도 한번에 많은 데이터를 불러오면, API 서버와 MongoDB 서버 모두에서 과도한 메모리를 사용하게 되고, 시스템이 다운되거나 성능이 저하될 수 있습니다. 그러나 여기서 skip 연산자를 무분별하게 사용할 때도 성능 저하가 발생될 수 있다는걸 알고 있나요? 저는 몰랐..
[NeetCode/Python] Is Palindrome
·
카테고리 없음
문제: https://neetcode.io/problems/is-palindrome NeetCode neetcode.io [내 풀이]class Solution: def isPalindrome(self, s: str) -> bool: s = ''.join(x for x in s if x.isalnum()).lower() for i in range(len(s)//2): l = 0 + i r = len(s) - 1 - i if s[l] == s[r]: pass else: return False return True python은 코테 언..
[NeetCode/Python] Invert a Binary Tree
·
카테고리 없음
문제: https://neetcode.io/problems/invert-a-binary-tree NeetCode neetcode.io [내 코드]# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: if not root: return ..