Skip to content
This repository was archived by the owner on Jun 19, 2020. It is now read-only.

Commit a580d9d

Browse files
authored
Create GenomicRangeQuery.md
1 parent ca66e48 commit a580d9d

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
- [GenomicRangeQuery](https://app.codility.com/programmers/lessons/5-prefix_sums/genomic_range_query/)
2+
3+
## 접근 방법
4+
5+
6+
# 첫번 째 방법
7+
1. 비교를 쉽게 하기 위해서 String[]을 int[]로 변환 한다.
8+
2. 변환시 for문을 최대한 적게 돌기 위하여 탐색에 필요한 부분만 변환한다.
9+
3. p값과 q값에서 최소 값을 찾는다.
10+
# 두번 째 방법
11+
12+
## 소스코드
13+
14+
~~~java
15+
public int[] solution(String s, int[] p, int[] q){
16+
int intS[] = new int[s.length()];
17+
int result[] = new int[p.length];
18+
19+
for(int i=0;i<p.length;i++){
20+
result[i] = this.getMinOfArray(s, p[i], q[i]);
21+
// System.out.println(result[i]);
22+
}
23+
return result;
24+
}
25+
26+
public int parserStringToInt(char str){
27+
switch(str){
28+
case 'A' : return 1;
29+
case 'C' : return 2;
30+
case 'G' : return 3;
31+
case 'T' : return 4;
32+
default : System.out.println("잘못된 문자열 값이 들어왔습니다.");
33+
return -1;
34+
}
35+
}
36+
public int getMinOfArray(String str, int start, int end){
37+
int min = 5;
38+
int parserInt = 0;
39+
for(int i=start;i<=end;i++){
40+
parserInt = this.parserStringToInt(str.charAt(i));
41+
if(min > parserInt){
42+
min = parserInt;
43+
if(parserInt == 1){
44+
return 1;
45+
}
46+
}
47+
}
48+
return min;
49+
}
50+
~~~
51+
52+
## 개선필요한 사항
53+
1. String[] ->int[] parser를 미리 하는게 좋을 것 같다. ( 중복되서 parser를 하는 듯 하다. )
54+
2. 시간복잡도가 N*M이므로 줄여야 된다.
55+
56+
57+
## 시간복잡도를 주링기 위해 생각한 점, 반영한 점
58+
1. 탐색해야되는 길이(M)만큼 for문을 돌면 안되고, 바로 값을 알 수 있는 연산이 필요하다. 즉, 2~4라고 가정했을 때 탐색없이 답을 찾아야 한다.
59+
60+
## 채점 결과
61+
| Task Score | Correctness | Performance |
62+
| ------------ | ------------- | ------------- |
63+
| 62% | 100% | 0% |

0 commit comments

Comments
 (0)