본문 바로가기

전체 글105

[JPA] 1:N 관계 테이블의 특정 컬럼 조회 Introduction 1:N 관계의 두 테이블이 존재하고 두 테이블 사이의 외래 키가 존재할 때, 해당 외래 키를 기준으로 특정 컬럼의 값들을 JPA를 통해 가져오려면 어떻게 해야 하는지 알아보려고 한다. 1: N 관계 설정 먼저 외래키 sub_id를 가지고 있는 1대 N 관계는 다음과 같이 설정을 해준다. 1 엔티티 public class Subscribe { @Id @Column(name = "sub_id") private Long id; ~ } N 엔티티 public class How_sub { ~ @ManyToOne @JoinColumn(name = "sub_id") private Subscribe subscribe; } public interface HowSubRepository extends.. 2023. 8. 4.
11725_트리의 부모 찾기 ▶ 실버 2 (트리) 문제 풀이 처음엔 queue 를 선언하여 parent 배열이 다 채워질 때까지 노드 쌍을 queue에 다시 삽입하는 방법을 생각했다. 하지만 O(N^2) 시간복잡도로 시간 초과가 났다. 그래서 bfs, dfs 중 bfs를 이용하여 풀었다. 코드 #include #include #include #include #include #include #include #define MAX 100001 using namespace std; int n; vector tree[MAX]; queue q; bool visited[MAX]; int parent[MAX]; void bfs() { q.push(1); while(!q.empty()) { int start = q.front(); q.pop(); .. 2023. 8. 4.
[React-Native] Firebase에 이미지 업로드 Instroduction Firebase의 storage에 이미지를 업로드하는 방법을 알아보려고 한다. // result {"assets": [{"fileName": "rn_image_picker_lib_temp_a56ab75e-5409-4700-8f51-6a4611a148ae.jpg", "fileSize": 199797, "height": 1280, "type": "image/jpeg", "uri": "file:///data/user/0/com.android_rn/cache/rn_image_picker_lib_temp_a56ab75e-5409-4700-8f51-6a4611a148ae.jpg", "width": 960}]} 이미지를 선택하고 나서 result로 출력되는 객체는 다음과 같다. 여기서 fil.. 2023. 6. 1.
[Python] Deep copy & shallow copy Deep copy & shallow copy mutable container인 list, set, dictionary 를 immutable 한 클래스를 만들기 위한 방법 Shallow copy b = a a와 b가 동일한 메모리 주소를 가짐 내부의 객체 또한 동일한 메모리 주소 # shallow copy a = [0, 1, [10, 20]] **b = a # 첫 번째 방법** b[0] = 'hello' b[-1][0] *= -1 print(a, b) # a = ['hello', 1, [-10, 20]], b = ['hello', 1, [-10, 20]] print(id(a), id(b)) # 동일한 아이디 값 print(id(a[2]), id(b[2])) # 내부의 리스트를 아이디 값이 같다 b = a[.. 2023. 4. 11.
[Python] Dictionary Dictionary key와 value 값을 가지는 자료형 {key1: value1, key2: value2, key3: value3, …} 특징 value 값은 key 에 의해 인덱싱된다. 순서가 존재하지 않는다. 기본 형태 d = {'a': 1, 'b': 2, 'c': 3} # value 값 접근 d['a'] # 1 # value 값 수정 d['a'] = 10 # {'a': 10, 'b': 2, 'c': 3} # 원소 추가 d['d'] = 4 # {'a': 10, 'b': 2, 'c': 3, 'd': 4} # 원소 삭제 del d['b'] # {'a': 10, 'c': 3, 'd': 4} # key 값만 탐색 list(d.keys()) # ['a', 'c', 'd'] list{d.values()) #.. 2023. 4. 11.
[Python] Set 집합과 관련된 것을 쉽게 처리하기 위해 만든 자료형 set의 특징 중복을 허용하지 않는다 순서가 존재하지 않는다 ⇒ 인덱스로 원소 값에 접근할 수 없다. set 생성 # set 키워드 이용 s1 = set([1, 2, 3]) # {1, 2, 3} s2 = set("Hello") # {'e', 'H', 'l', 'o'} set 연산 집합 연산 a = set([0, 1, 2]) b = set([1, 2, 3, 4]) # union (합집합) print(a | b) # {0, 1, 2, 3, 4} print(a.union(b)) # {0, 1, 2, 3, 4} a |= b # a = {0, 1, 2, 3, 4} # intersection (교집합) print(a & b) # {1, 2} print(a.inte.. 2023. 4. 11.