파이썬12 f-string # 숫자에 콤마 표시 f"{price:,}" # 1000 -> 1,000 # 숫자 앞에 패딩 처리 f"{num:02}" # 1 -> 01 f"{num:03}" # 1 -> 001 2024. 3. 28. 235, Lowest Common Ancestor of a Binary Search Tree # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': """가장 작은 부모 찾기 경우의 수: * P, Q가 부모 노드 왼쪽에만 존재하는 경우 * P, Q가 부모 노드 오른쪽에만 존재하는 경우 * P는 부모 노드 왼쪽, Q는 부모 노드 오른쪽에 존재하는 경우 * P 또는 Q 중 하나가 루트 노드에 존재하는 경우 LCA, Lowes.. 2024. 2. 25. Python logging 파이썬에서도 날짜 별로, 특정 주기마다 로그 파일을 자동으로 생성할 수 있다.(trace Id도 설정하면 좋으련만...)구글링을 하면서 정리한 내용을 아래에 작성해보겠다..json, .yaml, .conf, .py 파일에서 로그 파일 설정을 할 수 있다.여기선 .conf를 사용하겠다.app/config/logger.conf[loggers]keys = root[handlers]keys = stream_handler, file_handler[formatters]keys = stream_formatter, file_formatter[logger_root]level = NOTSEThandlers = stream_handler, file_handlerqualname = propagate = 0# handler[h.. 2024. 2. 19. 217, Contains Duplicate 1. 브루트 포스 class Solution: def containsDuplicate(self, nums: List[int]) -> bool: """brute force Time Complexity: O(n^2) Space Complexity: O(1) Returns: Time Limit Exceeded """ _len = len(nums) for i in range(_len-1): temp = nums[i] for j in range(i+1, _len): if temp == nums[j]: return True return False 2. 정렬 class Solution: def containsDuplicate(self, nums: List[int]) -> bool: """sort 파이썬의 내장함수 .. 2024. 2. 19. 이전 1 2 3 다음