전체 글
  • 문제 https://leetcode.com/problems/merge-two-sorted-lists/ Merge Two Sorted Lists - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이코드 package SITE03_leetcode.easy; import SITE03_leetcode.common.ListNode; import java.util.HashMap; import java.util.Map; import java.util.Set; import ..

    Read more
  • Mac Local Mysql 설치 Mac 터미널 명령어 // 최신 업데이트 brew update // 설치 brew install mysql // mysql 설치 버전 확인 mysql --version // mysql server 시작 mysql.server start // 접속 mysql -uroot -p // 비번 설정 없음 엔터 Mysql 접속 후 데이터베이스 생성 // 데이터베이스 생성 create database westmalldb // 계정 생성 전 설정 CREATE USER 'root'@'%' IDENTIFIED BY 'root'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; // 계정 생성 create user 'westmal..

    Read more
  • 공통 Response ResponseDto.java package com.api.westmall.common; import lombok.Builder; import lombok.Getter; import lombok.Setter; @Getter @Setter @Builder public class ResponseDto { private int status; private String message; private T body; } CommonResponse.java package com.api.westmall.common; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springfr..

    Read more
  • 문제 https://leetcode.com/problems/permutations-ii/ Permutations II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이코드 package SITE03_leetcode.medium; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * https://leetcode.com/problems/permutations/ */ ..

    Read more
  • 파이프라인 병렬 실행 자바 8부터는 parallel 메서드만 한번 호출하면 파이프라인을 병렬 실행할 수 있는 스트림을 지원했다. 이를 올바르고 빠르게 작성하는 일은 여전히 어려운 작업이다. 동시성 프로그래밍을 할때는 안정성과 응답가능 상태를 유지하기 위해 애써야한다. 메르센 소수를 생성하는 프로그램 package com.java.effective.item48; import java.math.BigInteger; import java.util.stream.Stream; import static java.math.BigInteger.ONE; import static java.math.BigInteger.TWO; /** * 메르센 소수를 생성하는 코드 */ public class Main { public st..

    Read more
  • 문제 https://leetcode.com/problems/permutations/ Permutations - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이코드 package SITE03_leetcode.medium; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * https://leetcode.com/problems/permutations/ */ public..

    Read more
  • 스트림 반환타입 스트림은 for-each 반복을 제공하지 않는다. API를 스트림만 반환하도록 짜놓으면 반환된 스트림을 for-each로 반복하길 원하는 사용자는 불편하다. Stream 인터페이스는 Iterable 인터페이스가 정의한 추상 메서드를 전부 포함하고, Iterable 인터페이스가 정의한 방식대로 동작한다. 그럼에도 for-each로 스트림을 반복할 수 없는 까닭은 Stream이 Iterable을 확장하지 않아서다. Iterator List list = List.of(1,2,3); Iterator iterator = list.iterator(); while(iterator.hasNext()) { system.out.println(iterator.next()); } 스트림의 경우에는 내부에 It..

    Read more
  • 문제 https://leetcode.com/problems/combination-sum/ Combination Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이코드 package SITE03_leetcode.medium; import SITE03_leetcode.common.ListNode; import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream..

    Read more
  • 스트림 패러다임 스트림은 그저 또 하나의 API 가 아닌, 함수형 프로그래밍에 기초한 패러다임이다. 스트림이 제공하는 표현력, 속도, 병렬성을 얻으려면 API는 말할것도 없고 이 패러다임까지 함께 받아들여야 한다. 스트림 패러다임의 핵심은 일련의 변환 (transformation)으로 재구성하는 부분이다. 이때 각 변환 단계는 가능한 한 이전 단계의 결과를 받아 처리하는 순수 함수여야 한다. * 순수함수 오직 입력만이 결과에 영향을 주는 함수로, 다른 가변 상태를 참조하지 않고, 함수 스스로도 다른 상태를 변경하지 않는다. 스트림에서는 순수함수여야 하기 때문에 스트림 연산에 건네는 함수 객체에 모두 부작용이 없어야한다. 예제 텍스트 파일에서 단어별 수를 세어 빈도표를 만드는 예제 스트림 패러다임을 이해하..

    Read more
  • 문제 https://leetcode.com/problems/majority-element/ Majority Element - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이코드 package SITE03_leetcode.easy; import SITE03_leetcode.medium.M004_leetCode4_median_of_two_sorted_arrays; import java.util.*; import java.util.stream.Collectors;..

    Read more
  • 들어가기전 스트림의 기본 개념은 숙지해야한다. 스트림 기본개념 포스팅 바로가기 https://devfunny.tistory.com/341 스트림의 기본개념 도입 모든 자바 애플리케이션은 컬렉션을 만들고 처리하는 과정을 포함한다. 컬렉션은 대부분의 프로그래밍 작업에 사용될 정도로 어디서든 사용되어지고있다. 하지만 컬렉션을 많이 사용함에 devfunny.tistory.com 스트림 스트림 API는 다량의 데이터 처리 작업을 위해 추가되었다. 이 API가 제공하는 추상 개념 중 핵심은 두가지다. 1) 스트림은 데이터 원소의 유한 혹은 무한 시퀀스를 뜻한다. 2) 스트림 파이프라인(stream pipeline)은 이 원소들로 수행하는 연산 단계를 표현하는 개념이다. 스트림의 파이프 라인은 소스 스트림에서 시작하..

    Read more
  • 함수형 매개변수 타입 자바가 람다를 지원하면서 템플릿 메서드 패턴의 매력이 크게 줄었다. * 템플릿 메서드 패턴 상위 클래스의 기본 메서드를 재정의해 원하는 동작을 구현하는 디자인패턴 이를 대체하는 현대적인 해법은 같은 효과의 함수 객체를 받는 정적 팩터리나 생성자를 제공하는 것이다. 이때 함수형 매개변수 타입을 올바르게 선택해야한다. LinkedHashMap 의 protect 메서드인 removeEldestEntry 를 재정의하면 캐시로 사용할 수 있다. 맵에 새로운 키를 추가하는 put 메서드는 이 메서드를 호출하여 true가 반환되면 맵에서 가장 오래된 원소를 제거한다. LinkedHashMap의 removeEldestEntry() ... /** * Sample use: this override w..

    Read more
  • 문제 https://leetcode.com/problems/remove-nth-node-from-end-of-list/ Remove Nth Node From End of List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이코드 package SITE03_leetcode.medium; import SITE03_leetcode.common.ListNode; /** * https://leetcode.com/problems/4sum/submissions/ *..

    Read more
  • 메서드 참조 자바 8부터 등장한 람다는 익명 클래스보다 간결하다. 자바에는 함수 객체를 람다보다도 더 간결하게 만드는 방법이 있는데, 바로 메서드 참조(method reference) 다. map.merge(key, 1, (count, incr) -> count + incr); 이때 값이 키의 인스턴스 개수로 해석된다면 이 프로그램은 멀티셋(multiset)을 구현한게 된다. 1) key 가 없을 경우 : 1 2) key 가 있을 경우 : 기존 매핑값을 증가 Map.java 의 merge() default V merge(K key, V value, BiFunction

    Read more
  • 문제 https://leetcode.com/problems/4sum/ 4Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이코드 package SITE03_leetcode.medium; import java.util.*; /** * https://leetcode.com/problems/4sum/submissions/ */ public class M012_leetCode18_4Sum { public static void main(String[] args)..

    Read more
  • Copyright 2024. GRAVITY all rights reserved