From 7212c4be2335c29be453e18f509129244fee3700 Mon Sep 17 00:00:00 2001 From: SiYoungOh Date: Mon, 14 May 2018 18:07:03 +0900 Subject: [PATCH 01/14] Update issue templates --- .github/ISSUE_TEMPLATE/Bug_report.md | 35 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/Custom.md | 7 +++++ .github/ISSUE_TEMPLATE/Feature_request.md | 17 +++++++++++ 3 files changed, 59 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/Bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/Custom.md create mode 100644 .github/ISSUE_TEMPLATE/Feature_request.md diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md new file mode 100644 index 0000000..4de26c7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/Custom.md b/.github/ISSUE_TEMPLATE/Custom.md new file mode 100644 index 0000000..daf862c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Custom.md @@ -0,0 +1,7 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. + +--- + + diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md new file mode 100644 index 0000000..5384295 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 0e49c94cd00ac5583955884475d5c391ca3913de Mon Sep 17 00:00:00 2001 From: SiYoungOh Date: Fri, 18 May 2018 14:15:41 +0900 Subject: [PATCH 02/14] Create pull_request_template.md --- .github/PULL_REQUEST_TEMPLATE/pull_request_template.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md new file mode 100644 index 0000000..5146a14 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -0,0 +1,9 @@ +- [Problem link](실제 url을 적어요) + +## 접근 방법 +자유롭게 기술 + +## 채점 결과 +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 00% | 00% | 00% | From facedfcd460ab7a14af9e3f92a9257ce7e0dd0de Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sat, 9 Jun 2018 10:16:16 +0900 Subject: [PATCH 03/14] Add --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index dd00f5b..cb06e8e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # algorithmSolution Codility, HackerRank 등 코딩테스트 플랫폼에서 알고리즘 풀이 수련 + +## Log +- 2018/06/09 Lesson03,04 풀이 From a48f4fbce7f31a2a8324faacf2ec55925a056dac Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sat, 16 Jun 2018 22:20:06 +0900 Subject: [PATCH 04/14] [codility] lesson05 --- .../codility/lesson05/CountDiv.md.txt | 37 +++++++++++ .../codility/lesson05/CountDiv.md.txt.bak | 18 ++++++ .../codility/lesson05/PassingCars.md.txt | 63 +++++++++++++++++++ .../codility/lesson05/PassingCars.md.txt.bak | 61 ++++++++++++++++++ 4 files changed, 179 insertions(+) create mode 100644 hojin/Algorithm/codility/lesson05/CountDiv.md.txt create mode 100644 hojin/Algorithm/codility/lesson05/CountDiv.md.txt.bak create mode 100644 hojin/Algorithm/codility/lesson05/PassingCars.md.txt create mode 100644 hojin/Algorithm/codility/lesson05/PassingCars.md.txt.bak diff --git a/hojin/Algorithm/codility/lesson05/CountDiv.md.txt b/hojin/Algorithm/codility/lesson05/CountDiv.md.txt new file mode 100644 index 0000000..46f2ee1 --- /dev/null +++ b/hojin/Algorithm/codility/lesson05/CountDiv.md.txt @@ -0,0 +1,37 @@ +- [CountDiv](https:app.codility.com/programmers/lessons/5-prefix_sums/count_div/) + +## +# ù ° + 1. end start̿ k  + 2. ׸ start end k ٸ +1 . + +# ι ° + 1. 0 end k  ִ + 2. 0 start k  ִ + 3. start k ϶ +1 ߰Ѵ, : ð start ϱ⸦ ϱ + 4. (1)-(2) + +## ҽڵ + +~~~java +public int solution(int A, int B, int K) { + + return this.test(A, B, K); +} +public int test(int start, int end, int k){ + int temp = end/k - start/k; + if(temp%k==0){ + temp+=1; + } + return temp; +} +~~~ + +## + +## ð⵵ ָ , ݿ + +## ä +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 100% | 100% | 100% | diff --git a/hojin/Algorithm/codility/lesson05/CountDiv.md.txt.bak b/hojin/Algorithm/codility/lesson05/CountDiv.md.txt.bak new file mode 100644 index 0000000..a0ebe82 --- /dev/null +++ b/hojin/Algorithm/codility/lesson05/CountDiv.md.txt.bak @@ -0,0 +1,18 @@ +- [CountDiv](https:app.codility.com/programmers/lessons/5-prefix_sums/count_div/) + +## +# ù ° + 1. end start̿ k  + 2. ׸ start end k ٸ +1 . + + +# ι ° + 1. 0 end k  ִ + 2. 0 start k  ִ + 3. start k ϶ +1 ߰Ѵ, : ð start ϱ⸦ ϱ + 4. (1)-(2) + +## ä +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 100% | 100% | 100% | diff --git a/hojin/Algorithm/codility/lesson05/PassingCars.md.txt b/hojin/Algorithm/codility/lesson05/PassingCars.md.txt new file mode 100644 index 0000000..b40d257 --- /dev/null +++ b/hojin/Algorithm/codility/lesson05/PassingCars.md.txt @@ -0,0 +1,63 @@ +- [PassingCars](https://app.codility.com/programmers/lessons/5-prefix_sums/passing_cars/) + +## +# ù ° + 1. Է 迭 0 ε Ǵ 迭 int zero[] + 2. Է 迭 1 ε Ǵ 迭 int one[] + 3. ̽ + 1. (P,Q) P < Q ִ + 2. ̸ ذϱ ؼ (1),(2) ۾ + 3. if(zero[i] > one[j]) Ž ϰ i++ (ݺ). ( 迭 Է 迭 ε ϰ ִ. ) + + +# ι ° + ù° 2 for  ʿ + `P < Q ذϱ` + 1. (P,Q) Ѵ + 1. P 0 Է 迭 ε + 2. Q 0 Է 迭 ε + 2. Q n Ѵ. + 1. P ε Q ȴ. ( P < Q ) --> n = n-1 + +## ҽڵ + +~~~java + public int solution(int[] A) { + // write your code in Java SE 8 + return this.test(A); + } + + public int test(int[] a){ + int zeroCnt = 0; + int oneCnt = 0; + int total = 0; + for(int i=0; i1000000000){ + return -1; + } + if(a[i]==0){ + total += oneCnt; + }else{ + oneCnt--; + } + } +// System.out.println(total); + return total; + } +~~~ + +## + +## ð⵵ ָ , ݿ + +## ä +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 100% | 100% | 100% | diff --git a/hojin/Algorithm/codility/lesson05/PassingCars.md.txt.bak b/hojin/Algorithm/codility/lesson05/PassingCars.md.txt.bak new file mode 100644 index 0000000..607eaea --- /dev/null +++ b/hojin/Algorithm/codility/lesson05/PassingCars.md.txt.bak @@ -0,0 +1,61 @@ +- [PassingCars](https://app.codility.com/programmers/lessons/5-prefix_sums/passing_cars/) + +## +# ù ° + 1. Է 迭 0 ε Ǵ 迭 int zero[] + 2. Է 迭 1 ε Ǵ 迭 int one[] + 3. ̽ + 1. (P,Q) P < Q ִ + 2. ̸ ذϱ ؼ (1),(2) ۾ + 3. if(zero[i] > one[j]) Ž ϰ i++ (ݺ). ( 迭 Է 迭 ε ϰ ִ. ) + + +# ι ° + ù° 2 for  ʿ + `P < Q ذϱ` + 1. (P,Q) Ѵ + 1. P 0 Է 迭 ε + 2. Q 0 Է 迭 ε + 2. Q n ϰ. +## ҽڵ + +~~~java + public int solution(int[] A) { + // write your code in Java SE 8 + return this.test(A); + } + + public int test(int[] a){ + int zeroCnt = 0; + int oneCnt = 0; + int total = 0; + for(int i=0; i1000000000){ + return -1; + } + if(a[i]==0){ + total += oneCnt; + }else{ + oneCnt--; + } + } +// System.out.println(total); + return total; + } +~~~ + +## + +## ð⵵ ָ , ݿ + +## ä +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 100% | 100% | 100% | From 5a13e1bfc10914fb947627bce551cbc3140595c1 Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sat, 16 Jun 2018 22:27:31 +0900 Subject: [PATCH 05/14] =?UTF-8?q?md=20=ED=99=95=EC=9E=A5=EC=9E=90=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lesson05/{CountDiv.md.txt => CountDiv.md} | 0 .../codility/lesson05/CountDiv.md.txt.bak | 18 ------ .../{PassingCars.md.txt => PassingCars.md} | 0 .../codility/lesson05/PassingCars.md.txt.bak | 61 ------------------- 4 files changed, 79 deletions(-) rename hojin/Algorithm/codility/lesson05/{CountDiv.md.txt => CountDiv.md} (100%) delete mode 100644 hojin/Algorithm/codility/lesson05/CountDiv.md.txt.bak rename hojin/Algorithm/codility/lesson05/{PassingCars.md.txt => PassingCars.md} (100%) delete mode 100644 hojin/Algorithm/codility/lesson05/PassingCars.md.txt.bak diff --git a/hojin/Algorithm/codility/lesson05/CountDiv.md.txt b/hojin/Algorithm/codility/lesson05/CountDiv.md similarity index 100% rename from hojin/Algorithm/codility/lesson05/CountDiv.md.txt rename to hojin/Algorithm/codility/lesson05/CountDiv.md diff --git a/hojin/Algorithm/codility/lesson05/CountDiv.md.txt.bak b/hojin/Algorithm/codility/lesson05/CountDiv.md.txt.bak deleted file mode 100644 index a0ebe82..0000000 --- a/hojin/Algorithm/codility/lesson05/CountDiv.md.txt.bak +++ /dev/null @@ -1,18 +0,0 @@ -- [CountDiv](https:app.codility.com/programmers/lessons/5-prefix_sums/count_div/) - -## -# ù ° - 1. end start̿ k  - 2. ׸ start end k ٸ +1 . - - -# ι ° - 1. 0 end k  ִ - 2. 0 start k  ִ - 3. start k ϶ +1 ߰Ѵ, : ð start ϱ⸦ ϱ - 4. (1)-(2) - -## ä -| Task Score | Correctness | Performance | -| ------------ | ------------- | ------------- | -| 100% | 100% | 100% | diff --git a/hojin/Algorithm/codility/lesson05/PassingCars.md.txt b/hojin/Algorithm/codility/lesson05/PassingCars.md similarity index 100% rename from hojin/Algorithm/codility/lesson05/PassingCars.md.txt rename to hojin/Algorithm/codility/lesson05/PassingCars.md diff --git a/hojin/Algorithm/codility/lesson05/PassingCars.md.txt.bak b/hojin/Algorithm/codility/lesson05/PassingCars.md.txt.bak deleted file mode 100644 index 607eaea..0000000 --- a/hojin/Algorithm/codility/lesson05/PassingCars.md.txt.bak +++ /dev/null @@ -1,61 +0,0 @@ -- [PassingCars](https://app.codility.com/programmers/lessons/5-prefix_sums/passing_cars/) - -## -# ù ° - 1. Է 迭 0 ε Ǵ 迭 int zero[] - 2. Է 迭 1 ε Ǵ 迭 int one[] - 3. ̽ - 1. (P,Q) P < Q ִ - 2. ̸ ذϱ ؼ (1),(2) ۾ - 3. if(zero[i] > one[j]) Ž ϰ i++ (ݺ). ( 迭 Է 迭 ε ϰ ִ. ) - - -# ι ° - ù° 2 for  ʿ - `P < Q ذϱ` - 1. (P,Q) Ѵ - 1. P 0 Է 迭 ε - 2. Q 0 Է 迭 ε - 2. Q n ϰ. -## ҽڵ - -~~~java - public int solution(int[] A) { - // write your code in Java SE 8 - return this.test(A); - } - - public int test(int[] a){ - int zeroCnt = 0; - int oneCnt = 0; - int total = 0; - for(int i=0; i1000000000){ - return -1; - } - if(a[i]==0){ - total += oneCnt; - }else{ - oneCnt--; - } - } -// System.out.println(total); - return total; - } -~~~ - -## - -## ð⵵ ָ , ݿ - -## ä -| Task Score | Correctness | Performance | -| ------------ | ------------- | ------------- | -| 100% | 100% | 100% | From 83f8e3809551810338b13eb96cd020d4c142ec56 Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sun, 17 Jun 2018 09:01:55 +0900 Subject: [PATCH 06/14] =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codility/lesson05/PassingCars.md | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/hojin/Algorithm/codility/lesson05/PassingCars.md b/hojin/Algorithm/codility/lesson05/PassingCars.md index b40d257..f20d6fe 100644 --- a/hojin/Algorithm/codility/lesson05/PassingCars.md +++ b/hojin/Algorithm/codility/lesson05/PassingCars.md @@ -1,25 +1,25 @@ - [PassingCars](https://app.codility.com/programmers/lessons/5-prefix_sums/passing_cars/) -## -# ù ° - 1. Է 迭 0 ε Ǵ 迭 int zero[] - 2. Է 迭 1 ε Ǵ 迭 int one[] - 3. ̽ - 1. (P,Q) P < Q ִ - 2. ̸ ذϱ ؼ (1),(2) ۾ - 3. if(zero[i] > one[j]) Ž ϰ i++ (ݺ). ( 迭 Է 迭 ε ϰ ִ. ) +## 접근 방법 +# 첫번 째 방법 + 1. 입력 배열값 중 값이 0인 인덱스를 값으로 저장되는 배열을 만든다 int zero[] + 2. 입력 배열값 중 값이 1인 인덱스를 값으로 저장되는 배열을 만든다 int one[] + 3. 이슈사항 + 1. (P,Q)를 쌍으로 지정할 때 P < Q라는 조건이 있다 + 2. 이를 해결하기 위해서 (1),(2)를 작업함 + 3. if(zero[i] > one[j]) 일 경우 탐색을 종료하고 i++를 진행 함 (반복문). ( 각 배열의 값은 입력 배열의 인덱스를 저장하고 있다. ) -# ι ° - ù° 2 for  ʿ - `P < Q ذϱ` - 1. (P,Q) Ѵ - 1. P 0 Է 迭 ε - 2. Q 0 Է 迭 ε - 2. Q n Ѵ. - 1. P ε Q ȴ. ( P < Q ) --> n = n-1 +# 두번 째 방법 + 첫번째 방법은 2중 for문이 들어가기 때문에 개선이 필요함 + `P < Q 해결하기` + 1. 한 쌍의 기준을 (P,Q)로 정한다 + 1. P는 값이 0인 입력 배열의 인덱스 + 2. Q는 값이 1인 입력 배열의 인덱스 + 2. Q의 개수를 n개로 정한다. + 1. 현재 P의 인덱스보다 작은 Q값을 다 빼야 된다. ( P < Q 조건 때문 ) --> n = n-1 -## ҽڵ +## 소스코드 ~~~java public int solution(int[] A) { @@ -53,11 +53,11 @@ } ~~~ -## +## 개선사항 -## ð⵵ ָ , ݿ +## 시간복잡도를 주링기 위해 생각한 점, 반영한 점 -## ä +## 채점 결과 | Task Score | Correctness | Performance | | ------------ | ------------- | ------------- | | 100% | 100% | 100% | From ca66e4889d04ffc326c623cf6dee7dc40b126be6 Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sun, 17 Jun 2018 09:37:08 +0900 Subject: [PATCH 07/14] =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hojin/Algorithm/codility/lesson05/CountDiv.md | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hojin/Algorithm/codility/lesson05/CountDiv.md b/hojin/Algorithm/codility/lesson05/CountDiv.md index 46f2ee1..4c5f290 100644 --- a/hojin/Algorithm/codility/lesson05/CountDiv.md +++ b/hojin/Algorithm/codility/lesson05/CountDiv.md @@ -1,17 +1,17 @@ - [CountDiv](https:app.codility.com/programmers/lessons/5-prefix_sums/count_div/) -## -# ù ° - 1. end start̿ k  - 2. ׸ start end k ٸ +1 . +## 접근 방법 +# 첫번 째 방법 + 1. end와 start사이에 k가 몇번 들어가는지 구하자 + 2. 그리고 start와 end가 k로 나누어 떨어진다면 +1씩 해주자. -# ι ° - 1. 0 end k  ִ - 2. 0 start k  ִ - 3. start k ϶ +1 ߰Ѵ, : ð start ϱ⸦ ϱ - 4. (1)-(2) +# 두번 째 방법 + 1. 0부터 end까지 k의 몇배수 까지 들어갈 수 있는지 구하자 + 2. 0부터 start까지 k의 몇배수까지 들어갈 수 있는지 구하자 + 3. start가 k의 배수일때는 +1를 추가한다, 이유 : 문제 제시가 start를 포함한 범위부터 구하기를 제시하기 때문 + 4. (1)-(2)를 해주자 -## ҽڵ +## 소스코드 ~~~java public int solution(int A, int B, int K) { @@ -20,18 +20,18 @@ public int solution(int A, int B, int K) { } public int test(int start, int end, int k){ int temp = end/k - start/k; - if(temp%k==0){ + if(start%k==0){ temp+=1; } return temp; } ~~~ -## +## 개선사항 -## ð⵵ ָ , ݿ +## 시간복잡도를 주링기 위해 생각한 점, 반영한 점 -## ä +## 채점 결과 | Task Score | Correctness | Performance | | ------------ | ------------- | ------------- | | 100% | 100% | 100% | From a580d9dc9ddf6fac1f36d957e10c00e1dc1f362f Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sat, 30 Jun 2018 23:01:55 +0900 Subject: [PATCH 08/14] Create GenomicRangeQuery.md --- .../codility/lesson05/GenomicRangeQuery.md | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 hojin/Algorithm/codility/lesson05/GenomicRangeQuery.md diff --git a/hojin/Algorithm/codility/lesson05/GenomicRangeQuery.md b/hojin/Algorithm/codility/lesson05/GenomicRangeQuery.md new file mode 100644 index 0000000..3bb3302 --- /dev/null +++ b/hojin/Algorithm/codility/lesson05/GenomicRangeQuery.md @@ -0,0 +1,63 @@ +- [GenomicRangeQuery](https://app.codility.com/programmers/lessons/5-prefix_sums/genomic_range_query/) + +## 접근 방법 + + +# 첫번 째 방법 + 1. 비교를 쉽게 하기 위해서 String[]을 int[]로 변환 한다. + 2. 변환시 for문을 최대한 적게 돌기 위하여 탐색에 필요한 부분만 변환한다. + 3. p값과 q값에서 최소 값을 찾는다. +# 두번 째 방법 + +## 소스코드 + +~~~java +public int[] solution(String s, int[] p, int[] q){ + int intS[] = new int[s.length()]; + int result[] = new int[p.length]; + + for(int i=0;i parserInt){ + min = parserInt; + if(parserInt == 1){ + return 1; + } + } + } + return min; + } +~~~ + +## 개선필요한 사항 + 1. String[] ->int[] parser를 미리 하는게 좋을 것 같다. ( 중복되서 parser를 하는 듯 하다. ) + 2. 시간복잡도가 N*M이므로 줄여야 된다. + + +## 시간복잡도를 주링기 위해 생각한 점, 반영한 점 + 1. 탐색해야되는 길이(M)만큼 for문을 돌면 안되고, 바로 값을 알 수 있는 연산이 필요하다. 즉, 2~4라고 가정했을 때 탐색없이 답을 찾아야 한다. + +## 채점 결과 +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 62% | 100% | 0% | From 8b766e4b4ccc71183f497ec15b25a5cedb3a0838 Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sat, 30 Jun 2018 23:28:41 +0900 Subject: [PATCH 09/14] =?UTF-8?q?=EC=BD=94=EB=94=9C=EB=A6=AC=ED=8B=B0=20?= =?UTF-8?q?=EB=A0=88=EC=8A=A85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a1c2a23..ca03a54 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + + From f02292a32aa18699aee030bd1aadcd304b002b8f Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sun, 1 Jul 2018 09:57:49 +0900 Subject: [PATCH 10/14] =?UTF-8?q?=EC=BD=94=EB=94=9C=EB=A6=AC=ED=8B=B0=20?= =?UTF-8?q?=EB=A0=88=EC=8A=A85=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dd00f5b..aa344d4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # algorithmSolution Codility, HackerRank 등 코딩테스트 플랫폼에서 알고리즘 풀이 수련 + + From 3249b081a0a23edd5fdb1b2822c8cff25930c31f Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sat, 14 Jul 2018 18:18:40 +0900 Subject: [PATCH 11/14] lessoon06_2 --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 9453c28..cb06e8e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ # algorithmSolution Codility, HackerRank 등 코딩테스트 플랫폼에서 알고리즘 풀이 수련 -<<<<<<< HEAD - -======= ## Log - 2018/06/09 Lesson03,04 풀이 ->>>>>>> facedfcd460ab7a14af9e3f92a9257ce7e0dd0de From 1952d2748d4d02189c6212ec6bd35347f4aff2e8 Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sun, 22 Jul 2018 00:13:38 +0900 Subject: [PATCH 12/14] lesson06 --- hojin/Algorithm/codility/lesson06/Distinct.md | 63 +++++++++++++++++++ .../codility/lesson06/GenomicRangeQuery.md | 63 +++++++++++++++++++ hojin/Algorithm/codility/lesson06/Triangle.md | 34 ++++++++++ 3 files changed, 160 insertions(+) create mode 100644 hojin/Algorithm/codility/lesson06/Distinct.md create mode 100644 hojin/Algorithm/codility/lesson06/GenomicRangeQuery.md create mode 100644 hojin/Algorithm/codility/lesson06/Triangle.md diff --git a/hojin/Algorithm/codility/lesson06/Distinct.md b/hojin/Algorithm/codility/lesson06/Distinct.md new file mode 100644 index 0000000..f45227f --- /dev/null +++ b/hojin/Algorithm/codility/lesson06/Distinct.md @@ -0,0 +1,63 @@ +- [Distinct](https://app.codility.com/programmers/lessons/6-sorting/distinct/) + +## 접근 방법 +# 첫번 째 방법 + 1. 입력 배열값 중 값이 0인 인덱스를 값으로 저장되는 배열을 만든다 int zero[] + 2. 입력 배열값 중 값이 1인 인덱스를 값으로 저장되는 배열을 만든다 int one[] + 3. 이슈사항 + 1. (P,Q)를 쌍으로 지정할 때 P < Q라는 조건이 있다 + 2. 이를 해결하기 위해서 (1),(2)를 작업함 + 3. if(zero[i] > one[j]) 일 경우 탐색을 종료하고 i++를 진행 함 (반복문). ( 각 배열의 값은 입력 배열의 인덱스를 저장하고 있다. ) + + +# 두번 째 방법 + 첫번째 방법은 2중 for문이 들어가기 때문에 개선이 필요함 + `P < Q 해결하기` + 1. 한 쌍의 기준을 (P,Q)로 정한다 + 1. P는 값이 0인 입력 배열의 인덱스 + 2. Q는 값이 1인 입력 배열의 인덱스 + 2. Q의 개수를 n개로 정한다. + 1. 현재 P의 인덱스보다 작은 Q값을 다 빼야 된다. ( P < Q 조건 때문 ) --> n = n-1 + +## 소스코드 + +~~~java + public int solution(int[] A) { + // write your code in Java SE 8 + return this.test(A); + } + + public int test(int[] a){ + int zeroCnt = 0; + int oneCnt = 0; + int total = 0; + for(int i=0; i1000000000){ + return -1; + } + if(a[i]==0){ + total += oneCnt; + }else{ + oneCnt--; + } + } +// System.out.println(total); + return total; + } +~~~ + +## 개선사항 + +## 시간복잡도를 주링기 위해 생각한 점, 반영한 점 + +## 채점 결과 +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 100% | 100% | 100% | diff --git a/hojin/Algorithm/codility/lesson06/GenomicRangeQuery.md b/hojin/Algorithm/codility/lesson06/GenomicRangeQuery.md new file mode 100644 index 0000000..3bb3302 --- /dev/null +++ b/hojin/Algorithm/codility/lesson06/GenomicRangeQuery.md @@ -0,0 +1,63 @@ +- [GenomicRangeQuery](https://app.codility.com/programmers/lessons/5-prefix_sums/genomic_range_query/) + +## 접근 방법 + + +# 첫번 째 방법 + 1. 비교를 쉽게 하기 위해서 String[]을 int[]로 변환 한다. + 2. 변환시 for문을 최대한 적게 돌기 위하여 탐색에 필요한 부분만 변환한다. + 3. p값과 q값에서 최소 값을 찾는다. +# 두번 째 방법 + +## 소스코드 + +~~~java +public int[] solution(String s, int[] p, int[] q){ + int intS[] = new int[s.length()]; + int result[] = new int[p.length]; + + for(int i=0;i parserInt){ + min = parserInt; + if(parserInt == 1){ + return 1; + } + } + } + return min; + } +~~~ + +## 개선필요한 사항 + 1. String[] ->int[] parser를 미리 하는게 좋을 것 같다. ( 중복되서 parser를 하는 듯 하다. ) + 2. 시간복잡도가 N*M이므로 줄여야 된다. + + +## 시간복잡도를 주링기 위해 생각한 점, 반영한 점 + 1. 탐색해야되는 길이(M)만큼 for문을 돌면 안되고, 바로 값을 알 수 있는 연산이 필요하다. 즉, 2~4라고 가정했을 때 탐색없이 답을 찾아야 한다. + +## 채점 결과 +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 62% | 100% | 0% | diff --git a/hojin/Algorithm/codility/lesson06/Triangle.md b/hojin/Algorithm/codility/lesson06/Triangle.md new file mode 100644 index 0000000..db3f4c1 --- /dev/null +++ b/hojin/Algorithm/codility/lesson06/Triangle.md @@ -0,0 +1,34 @@ +- [Triangle](https://app.codility.com/programmers/lessons/6-sorting/triangle/) + +## 접근 방법 + 1. 정렬이 된 상태면 아래 조건을 항상 만족 함 + 1. Q + R > P + 2. P + R > Q + 2. 그래서 추가적으로 P + Q > R 조건만 확인 하면 됨 + 3. long 형변환 이유는 Max int value일 경우 연산을 위하여 처리 함 + +## 소스코드 + +~~~java +public int solution(int[] a) { + Arrays.sort(a); + if(a.length >100000){ + return 0; + } + for (int i = 0; i < a.length - 2; i++) { + if ((long)a[i] + (long)a[i + 1] > (long)a[i + 2]) { + return 1; + } + } + return 0; + } +~~~ + +## 개선사항 + +## 시간복잡도를 주링기 위해 생각한 점, 반영한 점 + +## 채점 결과 +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 100% | 100% | 100% | From d415498b151c4f200d581e62c8c86ae873077bb7 Mon Sep 17 00:00:00 2001 From: HojinJava Date: Sun, 22 Jul 2018 00:34:28 +0900 Subject: [PATCH 13/14] lesson07 --- hojin/Algorithm/codility/lesson07/Brackets.md | 74 +++++++++++++++++++ hojin/Algorithm/codility/lesson07/Fish.md | 55 ++++++++++++++ hojin/Algorithm/codility/lesson07/Nesting.md | 47 ++++++++++++ .../Algorithm/codility/lesson07/StoneWall.md | 26 +++++++ 4 files changed, 202 insertions(+) create mode 100644 hojin/Algorithm/codility/lesson07/Brackets.md create mode 100644 hojin/Algorithm/codility/lesson07/Fish.md create mode 100644 hojin/Algorithm/codility/lesson07/Nesting.md create mode 100644 hojin/Algorithm/codility/lesson07/StoneWall.md diff --git a/hojin/Algorithm/codility/lesson07/Brackets.md b/hojin/Algorithm/codility/lesson07/Brackets.md new file mode 100644 index 0000000..40153d3 --- /dev/null +++ b/hojin/Algorithm/codility/lesson07/Brackets.md @@ -0,0 +1,74 @@ +- [Brackets](https://app.codility.com/programmers/lessons/7-stacks_and_queues/brackets/) + +## 접근 방법 + + +# 첫번 째 방법 + 1. 아스키코드값으로는 규칙이 안보여서 임의로 규칙을 생성한다. + 2. 같은 쌍 (ex: ']', '[')은 서로 값이 1차이 나도록 한다. + 3. 최근에 열린 괄호를 저장해두는 배열을 만든다.(openArray[]) + 4. 닫는 기호 " ']','}',')' "가 나왔을 경우 본인의 짝이 나온 값을 -1을 해준다. + 5. 최근의 연 기호가 본인의 짝인지 확인 한다. + +## 소스코드 + +~~~java +public int solution(String s) { + int[] cntArray = new int[6]; + int index = 0; + char[] c = s.toCharArray(); + int[] openArray = new int[c.length]; + int charCnt=0; + int recentIndex = 0; + int openIndex = 0; + for(int i=0; i< c.length ;i++ ){ + index = this.changeCharToTempInt(c[i]); + if(c[i] == '}' || c[i] == ']' || c[i] == ')'){ + //짝궁의 값을 -1 시킨다. + index--; + cntArray[index] += -1; + charCnt--; + if(cntArray[index] < 0){ + return 0; + } + //최근의 연 기호가 본인의 짝인지 확인한다. + openIndex--; + if(openArray[openIndex] == index){ + }else{ + //짝궁이 아니다 + return 0; + } + }else{ + cntArray[index] += 1; + charCnt++; + openArray[openIndex++] = index; + } + } + if(charCnt == 0) return 1; + return 0; + } + + public int changeCharToTempInt(char c){ + switch(c){ + case '{' : return 0; + case '}' : return 1; + case '[' : return 2; + case ']' : return 3; + case '(' : return 4; + case ')' : return 5; + default : new Exception(); return -1; + } + } +~~~ + +## 개선필요한 사항 + 1. 웬지 짝궁의 값을 -1시키는 부분은 필요가 없어보이는 듯 하다. + + +## 시간복잡도를 주링기 위해 생각한 점, 반영한 점 + + +## 채점 결과 +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 100% | 100% | 100% | diff --git a/hojin/Algorithm/codility/lesson07/Fish.md b/hojin/Algorithm/codility/lesson07/Fish.md new file mode 100644 index 0000000..ce26feb --- /dev/null +++ b/hojin/Algorithm/codility/lesson07/Fish.md @@ -0,0 +1,55 @@ +- [Fish](https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/) + +## 접근 방법 + - 0번째 물고기가 1번째 물고기보다 상류에 존재한다. + - 0은 상류 1은 하류를 의미한다. + - 기준 물고기를 정하자 ( 기준 물고기 : 다음 물고기랑 만날 물고기 ) + - 내려가는 물고기가 나올때까지 탐색을 한다 + - 내려가는 물고기를 만나면 이 물고기가 기준 물고기가 된다. + - 기준 물고기랑 다음 물고기를 비교한다. + - 같은 방향일 경우 기준 물고기가 다음 물고기로 변경된다. + - 다른 방향일 경우 한명이 잡혀 먹힌다. (올라가는 물고기) + 1. 잡아먹었을 경우 : 기준 물고기가 고정 + 2. 잡혀먹혔을 경우 : 기준 물고기는 사라진다. + - 다시 내려가는 물고기를 찾는다. + - 찾으면 기준물고기로정하고 위 로직을 반복한다. + +## 소스코드 + +~~~java +public int solution(int[] a, int[] b) { + int liveCnt=0; + int nowFish = 0; + int nextFish = 0; + int fixFish = 0; + for(int i=0; i nowFish){ + fixFish = nextFish; + }else{ + fixFish = nowFish; + } + }else{ + liveCnt++; + } + }else{ + + } + + } + return 0; + } +~~~ + +## 개선사항 + 1. 아직 문제를 정확하게 이해 하지 못했다. + +## 시간복잡도를 주링기 위해 생각한 점, 반영한 점 + +## 채점 결과 +| Task Score | Correctness | Performance | +| ------------ | ------------- | ------------- | +| 0% | 0% | 0% | diff --git a/hojin/Algorithm/codility/lesson07/Nesting.md b/hojin/Algorithm/codility/lesson07/Nesting.md new file mode 100644 index 0000000..15f35a9 --- /dev/null +++ b/hojin/Algorithm/codility/lesson07/Nesting.md @@ -0,0 +1,47 @@ +- [Nesting](https://app.codility.com/programmers/lessons/7-stacks_and_queues/nesting/) + +## 접근 방법 +# 첫번 째 방법 + 1. 열리는 괄호를 leftCnt로 체크 + 2. 닫히는 괄호를 rightCnt로 체크 + 3. 닫히는 괄호는 항상 열리는 괄호보다 작아야 한다. + 4. if문이 끝났을 때 열리는 괄호랑 닫히는 괄호 크기를 확인한다. + + + +## 소스코드 + +~~~java + public int solution(String s) { + int leftCnt = 0; + int rigthCnt = 0; + char c[] = s.toCharArray(); + for(int i=0; i Date: Sun, 5 Aug 2018 09:33:03 +0900 Subject: [PATCH 14/14] oncoder --- hojin/Algorithm/oncoder/Four.java | 5 ++ hojin/Algorithm/oncoder/One.java | 30 +++++++ hojin/Algorithm/oncoder/Three.java | 76 +++++++++++++++++ hojin/Algorithm/oncoder/Two.java | 128 +++++++++++++++++++++++++++++ 4 files changed, 239 insertions(+) create mode 100644 hojin/Algorithm/oncoder/Four.java create mode 100644 hojin/Algorithm/oncoder/One.java create mode 100644 hojin/Algorithm/oncoder/Three.java create mode 100644 hojin/Algorithm/oncoder/Two.java diff --git a/hojin/Algorithm/oncoder/Four.java b/hojin/Algorithm/oncoder/Four.java new file mode 100644 index 0000000..ac81162 --- /dev/null +++ b/hojin/Algorithm/oncoder/Four.java @@ -0,0 +1,5 @@ +package oncoder; + +public class Four { + +} diff --git a/hojin/Algorithm/oncoder/One.java b/hojin/Algorithm/oncoder/One.java new file mode 100644 index 0000000..edaf4dc --- /dev/null +++ b/hojin/Algorithm/oncoder/One.java @@ -0,0 +1,30 @@ +package oncoder; + +public class One { + static public void main(String[] args){ + System.out.println(new One().decryptSpell("OnCoder")); + } + public String decryptSpell(String str){ + if(str.length()<1 || str.length()>100){ + return ""; + } + if(str.length()==2){ + return str; + } + + char[] charArray = str.toCharArray(); + char[] resultChar = str.toCharArray(); + for(int i=2; i= 97 && + (int)charArray[i] <=122){ + //소문자다 + //대문자로 변경 + resultChar[i] = (char) ((char)((int)charArray[i])-(32)); + }else{ + //느낌표로 변경 + resultChar[i] = '!'; + } + } + return String.valueOf(resultChar); + } +} diff --git a/hojin/Algorithm/oncoder/Three.java b/hojin/Algorithm/oncoder/Three.java new file mode 100644 index 0000000..7f800e7 --- /dev/null +++ b/hojin/Algorithm/oncoder/Three.java @@ -0,0 +1,76 @@ +package oncoder; + +public class Three { + public static void main(String[] args) { + + } + public String encoder(String message){ + char[] messageChar = message.toCharArray(); + int[] encoder = new int[message.length()]; + String binaryStr = ""; + String total = ""; + for(int i=0; i 0){ + retrunStr += "0"; + zeroCnt--; + } + return str+retrunStr; + } + public String parserBinaryTo6bit(String binaryStr){ + if(binaryStr.length()>1){ + if(binaryStr.indexOf("0")==0){ + binaryStr = binaryStr.substring(1,binaryStr.length()); + } + } + int zeroCnt = 6-binaryStr.length(); + String retrunStr = ""; + while(zeroCnt > 0){ + retrunStr += "0"; + zeroCnt--; + } + return retrunStr+binaryStr; + } + + public int parserCharToInt(char val){ + int checkVal = val; + if(checkVal >= 97 && checkVal <=122){ + return checkVal-97; + }else if(checkVal >= 65 && checkVal <=90){ + return checkVal-39; + }else if(checkVal >= 48 && checkVal <=57){ + return checkVal+4; + }else{ + return 62; + } + } +} diff --git a/hojin/Algorithm/oncoder/Two.java b/hojin/Algorithm/oncoder/Two.java new file mode 100644 index 0000000..02f914c --- /dev/null +++ b/hojin/Algorithm/oncoder/Two.java @@ -0,0 +1,128 @@ +package oncoder; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.ValidationEvent; + +public class Two { + + static public void main(String[] args) { +// new Two().getHashM(1007,3); + System.out.println(new Two().getHashM(88445,10)); + } + + public int getHashM(int maxK, int collision) { + int l = maxK / collision; + if(l<2){ + return 2; + } + int n = 0; + int xn = 0; + boolean flag = false; + while(true){ + if(this.getN(l, Math.pow(2, n),Math.pow(2, n+1))){ + flag = true; + } + if(flag){ + if(this.getN(l, Math.pow(2, n+1),Math.pow(2, n+2))){ + flag = false; + }else{ + xn = n; + break; + } + } + n++; + } + //소수 찾기 + int middel = (int)((Math.pow(2, n) + Math.pow(2, n+1))/2); + int cnt=0; + int min = 10000; + int val = 0; + List valList = new ArrayList(); + valList.add(2); + for(int i=(int)Math.pow(2, n); i<(int)Math.pow(2, n+1) ; i++){ + for(int j=0;j Math.abs( middel-i)){ + min = Math.abs( middel-i); + val = i; + } + } + cnt=0; + } + for(int temp:valList){ + if(min > Math.abs( middel-temp)){ + min = Math.abs( middel-temp); + val = temp; + } + } + return val; + } + + public boolean getN(int key, double d, double e){ + if(d <= key && key <= e){ + return true; + } + return false; + } +// public int getHashM(int maxK, int collision) { +// int l = maxK / collision; +// if(l<2){ +// return 2; +// } +// int n = 0; +// int xn = 0; +// boolean flag = false; +// while(true){ +// if(this.getN(l, Math.pow(2, n),Math.pow(2, n+1))){ +// flag = true; +// } +// if(flag){ +// if(this.getN(l, Math.pow(2, n+1),Math.pow(2, n+2))){ +// flag = false; +// }else{ +// xn = n; +// break; +// } +// } +// n++; +// } +// //소인수 찾기 +// int middel = (int)((Math.pow(2, n) + Math.pow(2, n+1))/2); +// int cnt=0; +// int min = 10000; +// int val = 0; +// for(int i=(int)Math.pow(2, n); i<(int)Math.pow(2, n+1) ; i++){ +// for(int j=2;j Math.abs( middel-i)){ +// min = Math.abs( middel-i); +// val = i; +// } +// } +// cnt=0; +// } +// return val; +// } +// +// public boolean getN(int key, double d, double e){ +// if(d <= key && key <= e){ +// return true; +// } +// return false; +// } + +}