문제

asc로 정렬된 인티저 배열이 제공되고 더 했을때의 합이 타겟과 같은 두개의 숫자가 몇번째 배열인지 리턴하라

 

Input: numbers = [2,7,11,15], target = 9

Output: [1,2] Explanation: The sum of 2 and 7 is 9.

Therefore index1 = 1, index2 = 2.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
    public int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
 
            if (i != nums.length) {
                for (int j = i+1; j < nums.length; j++) {
                    int res = nums[i] + nums[j];
                    if (res == target) {
                        return new int[] { i+1, j+1 };
                    }
                }
            }
 
        }
        return nums;
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

시간복잡도 O(n^2)

문제 인티저의 배열이 주어졌을때 더했을때의 합이 target의 숫자와 일치하는 두개의 숫자의 인덱스 번호를 리턴시켜라

 

Given nums = [2, 7, 11, 15], target = 9,

 

Because nums[0] + nums[1] = 2 + 7 = 9,

return [0, 1].

 

내가 푼 답

 

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
    public int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if (nums[j] == target - nums[i]) {
                    return new int[] { i, j };
                }
            }
 
        }
        return nums;
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

시간복잡도 O(n^2)

jpa 인강을 보던중 똑같이 따라했건만 h2 db의 table이 초기화가 되지 않는 현상을 발견

버전을 보니 내 버전은 1.4.200이고 강사님껀 더 낮은버전이였다.

 

그래서 검색을 해봤다.

 

https://stackoverflow.com/questions/59364212/integrationtest-isolation-fails-in-springboot-2-2-2-release-error-dopping-table

 

IntegrationTest isolation fails in springboot 2.2.2.RELEASE (Error dopping tables after each SpringBootTest)

Our app is working in 2.0.4 release. After upgrade to 2.2.2.RELEASE we see integration tests failing. I suspect that there is some misconfiguration, and each integration test simply does not clean ...

stackoverflow.com

 

보니까 이미 깃헙에 패치가 다 되어있었다

근데 1.4.200버전엔 적용이 안되있어서 스택오버플로우에 나오는 깃헙주소로 들어가

따로 하이버네이트의 dialect 를 상속받은 커스텀 dialect 클래스를 만들어 프로퍼티에 추가시켜주니

잘작동하는걸 확인했다.

 

참고로 위의 스택오버플로우 주소에 있는 커스텀 dialect를 그대로 가져다쓰면 안되고 (전 안됬음)

깃헙에 수정된 소스를 보고 맞춰서 수정해줘야됨

db 파일생성방법

1. url로 접속 한 후 jdbc:h2:~/xxxx 로 세션키 유지한상태로 접속한다.

2.xxxx.mv.db파일 생성을 확인한다

3.이후는 jdbc:h2:tcp://localhost/~/xxxx로 접속한다.

'개발 > db' 카테고리의 다른 글

mysql 데이터타입 - 실수  (0) 2020.04.19

Hibernate

 

1. dialect (hibernate 전용옵션)

 

각 데이터베이스 벤더마다 문법들이 다르기 때문에 어떤 데이터베이스를 사용하는지 설정하면

jpa가 적용해서 알아서 맞춰줌

 

h2 : org.hibernate.dialect.H2Dialect

 

oracle 1xg : org.hibernate.dialect.Oracle1xgDialect

 

Mysql : org.hibernate.dialect.MySQL5Dialect

 

 

 

 

 

'개발 > jpa' 카테고리의 다른 글

Repository Interface에 @Respoitory가 없는 이유  (0) 2020.08.15
post 와 comment 내가 선택한 출력 방식  (0) 2020.06.02

퍼시스턴스.xml 파일에

javax.persistence.jdbc.url에 tcp를 안넣을경우 다중접속이 불가능함

 

1.webfulx랑 같이 키면 에러남

 

2.spring web 버전이 2.2.4일때 admin server랑 client버전은 2.0.1쓰면안되고 2.2.2써야됨

dockerfile 도커의 작업지시서 이미지 빌드를 어떻게 할것인가 적어놓는곳

 

FROM centos:7

WORKDIR /app

COPY 1.txt

CMD cat 1.txt

 

base로 쓸 도커 이미지는 centos7버전

이미지 컨테이너의 내부 디렉토리 /app으로 설정

1.txt파일을 workdir로 지정한 이미지 컨테이너의 내부 디렉토리로 복사

cat 1.txt 명령어를 컨테이너에서 실행

 

FROM은 base로 쓸 도커 이미지 이름을 적고

WORKDIR 은 이미지 컨테이너 내부의 디렉토리를 지정하고

COPY는 호스트에서 이미지 컨테이너로 복사할 파일을 지정

CMD는 이미지 컨테이너에서 실행할 명령어를 입력

 

 

docker build -t ds/dsimage:1.0 .

 

ds 이름

dsimage 이미지이름

1.0 버전

. 경로 (현재위치)

'개발 > docker' 카테고리의 다른 글

Linux Container  (0) 2021.03.03
docker-compose.yml 작성  (0) 2020.06.18
내가 자주쓰는 docker 명령어  (0) 2020.02.23
centos 7 docker 설치  (0) 2020.02.23
centos 6.10 docker 설치  (0) 2020.02.23

+ Recent posts