개발하는 쿠키
article thumbnail
Java, LeetCode | 35. Search Insert Position
Coding/algorithm 2024. 7. 23. 23:48

🚀 풀이 후기이진 탐색 문제를 오랜만에 푸니까 요령이 생겼습니다.항상 헷갈렸던 부분이 else if 구문에서 어느 조건에 answer 답변을 세팅해줘야 하는지였습니다.아래 문제에서 Example 2를 보면 nums[i]  일 때 answer = i+1 을 넣어주므로, 코드를 짤 때, target  nums[i] 인 조건에서 answer = i 를 세팅해주면 됩니다. 🌒 문제 설명Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You must..

article thumbnail
Java, BaekJoon | 27866. 문자와 문자열
Coding/algorithm 2024. 7. 23. 01:07

🚀 풀이 후기자바에서 String의 특정 index 에 있는 문자를 가져올 때 쓰는 함수는 `string.charAt(index)` 입니다.🌒 문제 설명🌓 문제 풀이import java.io.IOException;import java.io.BufferedReader;import java.io.InputStreamReader;public class Main{ public static void main(String[] args) throws IOException{ BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); ..

article thumbnail
Java, LeetCode | 27. Remove Element
Coding/algorithm 2024. 7. 23. 01:00

🚀 풀이 후기반환해야 하는 수 k를 "제거한 수의 개수" 로 잘못 해석했습니다.k = "제거하고 남은 수의 개수" 입니다.🌒 문제 설명Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the foll..

article thumbnail
Java, BaekJoon | 31403. $A + B - C$
Coding/algorithm 2024. 7. 21. 13:29

🚀 풀이 후기오랜만에 알고리즘을 푸니까 BufferedReader, InputStreamReader로 인풋을 만드는 방법을 까먹었더라고요. 🥲🌒 문제 설명🌓 문제 풀이import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Main { // 변수 A, B, C를 정의합니다. static int a, b, c; public static void main(String[] args) throws IOException { // BufferedReader를 이용해 A, B, C 를 입력받습니다. BufferedReader br = new Buffere..

article thumbnail
Java, LeetCode | 26. Remove Duplicates from Sorted Array
Coding/algorithm 2024. 7. 21. 13:02

🚀 풀이 후기정답인지 검사할 때, 함수의 반환 자료형인 int 의 값과, 인풋이었던 nums 를 모두 확인한다는 부분이 신기했습니다.🌒 문제 설명Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.Consider the number of unique elements of nums to be k, to get ac..

article thumbnail
JPA | 15장. 프록시 심화 주제, 성능 최적화
Coding/computer science 2024. 1. 18. 03:29

프록시 심화 주제 영속성 컨텍스트와 프록시 영속성 컨텍스트는 자신이 관리하는 영속 엔티티의 동일성(==)을 보장한다. 그럼 프록시로 조회한 엔티티의 동일성도 보장할까? @Test public void 영속성컨텍스트와_프록시1() { Team team1 = Team.builder() .name("team1") .build(); em.persist(team1); em.flush(); em.clear(); Team refTeam = em.getReference(Team.class, team1.getId()); // 프록시를 이용한 방법 Team findTeam = em.find(Team.class, team1.getId()); // 영속성 컨텍스트 이용한 방법 System.out.println("refTeam..

article thumbnail
JPA에서 Page 기능 사용하기
Coding/computer science 2023. 11. 23. 11:18

👊 시작하기 이번 글을 통해 JPA Page와 Pageable interface 비교해보고, Paging 최적화 방법에 대해 알아보겠습니다. JPA 페이징 API TypedQuery query = em.createQuery("SELECT m FROM Member m ORDER BY m.username DESC", Member.class); query.setFirstResult(10); query.setMaxResults(20); query.getResultList(); JPA 는 페이징을 2개의 API로 추상화합니다. setFirstResult(int startPosition) : 조회 시작 위치(0부터 시작) setMaxResults(int maxResult): 조회할 데이터 수 setFirstResu..

article thumbnail
자바 ORM 표준 JPA 프로그래밍 | 10. 객체지향 쿼리 언어
Coding/computer science 2023. 11. 16. 12:11

이번 장을 읽으면서 em.find() vs JPQL select 차이와 JPA flush에 대해 정리한다. em.find() vs JPQL select em.find(Member.class, 1L); em.find(Member.class, 1L); 이 코드를 실행하면 데이터베이스에 쿼리가 몇 번 실행될까? 답은 한 번이다. JPA 의 em.find() 를 실행하면 영속성 컨텍스트에 해당 엔티티가 있는지 검사한다. 영속성 컨텍스트에 엔티티가 있으면 그 엔티티를 반환하고, 없으면 데이터베이스에 조회 쿼리를 실행 > 영속성 컨텍스트에 저장 > 반환한다. em.find(Member.class, 1L); em.createQuery("select m from Member m where m.id = 1") .getS..

반응형