| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
- LeetCode
- 오블완
- GNN
- sort
- Data_Structure
- Mesh
- code
- 데이터베이스
- CNN
- 데이터
- 코딩테스트
- 티스토리챌린지
- 컴퓨터공학
- 컴퓨터사이언스
- mysql
- Leet Code
- coding
- Database
- 개발자
- Python
- 대학생
- adaptive remeshing
- DS
- 코테
- meshgraphnet
- 자료구조
- SQL
- 데베
- db
- CS
- Today
- Total
목록Python (9)
sy1214ei 님의 블로그
1. 입출력 (Input/Output)실수 포인트: 데이터 양이 많은 문제에서 input()을 사용해 '시간 초과(TLE)' 발생.해결책: sys.stdin.readline을 사용하여 입력 속도를 최적화한다.import sysinput = sys.stdin.readline # 습관적으로 맨 위에 선언# 숫자 하나 읽기n = int(input())# 공백으로 구분된 여러 숫자 리스트로 읽기nums = list(map(int, input().split()))# 여러 줄에 걸쳐 들어오는 숫자들을 한꺼번에 읽기data = list(map(int, sys.stdin.read().split()))2. 인덱스 순환 구조 (Circular Index)실수 포인트: 리스트 끝에서 다시 앞으로 돌아갈 때 while이나 i..
https://leetcode.com/problems/keyboard-row/description/level : easyclass Solution: def findWords(self, words: List[str]) -> List[str]: set1 = {'q','w','e','r','t','y','u','i','o','p'} set2 = {'a','s','d','f','g','h','j','k','l'} set3 = {'z','x','c','v','b','n','m'} res = [] for i in words: wordset = set(i.lower()) if (wordset&se..
level : Mediumclass Solution: def lengthOfLongestSubstring(self, s: str) -> int: """ 슬라이딩 윈도우 - 부분 문자열에 중복 문자 X: end += 1 - 부분 문자열에 중복 문자 O: start += 1 """ max_len = 0 start, end = 0, 0 chars = set() while end
https://leetcode.com/problems/intersection-of-two-arrays/description/level : Easyclass Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: """ 1. nums1에 있는 값은 모두 True 2. nums2에 nums1에 있는 값이 있다면 res.add 3. return list(res) : res에는 num1, num2의 겹치는 값들 다 들어감 """ hash_table = {} for num in nums1: hash_table[num..
https://leetcode.com/problems/first-missing-positive/Level : Hardclass Solution: def firstMissingPositive(self, nums: List[int]) -> int: # 1. 음수는 0으로 for i in range(len(nums)): if nums[i] 0: nums[val-1] *= -1 elif nums[val-1] == 0: nums[val-1] = -1 * (len(nums)+1) # 3. 제일 작은 양수 찾기 for i in..
def dfs(graph, start_node): visited = set() # 중복 탐색 방지 traversal = [] # 방문 순서 저장 stack = [start_node] # 1. curr = stack.pop() # 2. 만약 curr이 visited에 없다면 visited.add(curr) # 3. curr과 이웃한 노드 모두 stack에 넣기 while stack: curr = stack.pop() if curr not in visited: visited.add(curr) traversal.append(curr) for neibor in graph[curr]: stack.append(neibor) re..
https://leetcode.com/problems/longest-palindrome/description/Level : EasyTopics : Hash Table | String | Greedyclass Solution: def longestPalindrome(self, s: str) -> int: # "abccccdd" -> "dccaccd" "dccbccd" # 해쉬테이블로 각 char타입의 수를 count 해준다. # 각 문자별 저장되어있는 count가 짝수이면 -> length로 모두 사용 # count가 홀수이면 -> count-1만큼 length로 사용 char_cnt = {} ..
level : EasyTopics : Linked List | Recursionhttps://leetcode.com/problems/merge-two-sorted-lists/#Definition for singly-linked list.class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = nextclass Solution: def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: dummy = ListNode() # 더미 노드 생성 ..