본문 바로가기

분류 전체보기24

course schedule Course Schedule prerequisite : [a,b] = a course를 완료하기 위해 b course를 먼저 완료 해야함 numCourses : 코스 개수, prerequisites 가 주어졌을때 전부 완료가능하면 True 아니면 False Solution1 각 course 를 node 로 prerequisite 를 edge 로 생각하면 directed graph로 표현가능 directed graph에 cycle 이 존재하는 지 판별해서 존재하는 경우 False, 없으면 True dfs를 이용해 한 노드에서 출발하는 경로중에 cycle이 존재하는 지 검사할수 있음(has_cycle) 방문한 노드 기록(visitied) 해당 노드를 출발점으로 하는 어떤 경로에도 cycle이 없다고 결정(f.. 2022. 1. 21.
Table 상태(key, index 조회, 제약조건) Table 의 KEY, INDEX 조회 SHOW KEYS FROM tableName; -- key 조회 SHOW INDEX FROM tableName; -- index 조회 SHOW TABLE STATUS from dbName; -- db상에 존재하는 모든 테이블의 상태 참조 제약조건 조회 information_schema.referential_constraints 테이블에서 조회 SELECT * FROM information_schema.referential_constraints WHERE constraint_schema = 'DB 이름' and table_name='TABLE 이름'; 2022. 1. 18.
[leetcode] subset subset 한 집합이 주어질때 모든 부분집합을 리턴 solution1 itertools 의 combinations 이용 0 ~ len(nums) 크기의 조합 찾아서 결과값에 추가 code1 from itertools import combinations class Solution(object): def subsets(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ # nCr 에서 r = 0 , r = len(nums) 일때 result = [[],nums] # r = 1 ~ len(nums)-1 일때 for i in range(1,len(nums)): result.extend(list(map(list,combinations(nums,.. 2022. 1. 17.
[leetcode] combination sum combination sum 숫자 집합(candidates)과, target 숫자가 주어진다 숫자 집합의 숫자를 조합해서 target이 되는 모든 경우를 나열 숫자 집합의 원소를 여러번 사용할수 있다 solution dfs를 통해서 작은 원소부터 cur에 하나씩 추가 target에 도달하면 결과값에 포함 target을 초과하는 경우에는 탐색 종료 한 원소를 추가하면 다음 재귀 에서는 그 원소보다 작은 원소는 추가할수 없게 한다 code class Solution(object): def combinationSum(self, candidates, target): candidates = sorted(filter(lambda x : x target : break cur.append(el) dfs(cur,elem.. 2022. 1. 17.