공부는 끝이 없구나 5

[codility] 풀어보기 - PassingCars

Lesson 5-2 - PassingCars내용 : Count the number of passing cars on the road. 시간 복잡도 : O(n)정답 코드 :1234567891011121314function solution(A) { // write your code in JavaScript (Node.js 6.4.0) let rt=0; let eastcnt=0; for(i in A) { if(A[i] == 0) { eastcnt ++; } else { rt += eastcnt; } if(rt > 1000000000) { rt = -1; break; } } return rt;Colored by Color Scriptercs 동쪽과 서쪽 짝을 이루어야 되므로 구분해서 계산쉽지 않은 문제이런 방법..

알고리즘 2017.10.27

[codility] 풀어보기 - MaxCounters

Lesson 4-4 - MaxCounters내용 : Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.문제 설명은 여기를 참고 http://hojak99.tistory.com/316 시간 복잡도 : O(N+M)80% 코드 :function solution(N, A) { // write your code in JavaScript (Node.js 6.4.0) let rt_arr = new Array(N); let max_counter = 0; let now_idx=0; rt_arr.fill(0); for..

알고리즘 2017.10.18

[codility] 풀어보기 - PermMissingElem

Lesson 3-2 - PermMissingElem내용 :Find the missing element in a given permutation시간 복잡도 : O(N) 성공 했지만 민망해서 공개 안하는 코드 : function isZero(element) { return element == 1; } function solution(A) { // write your code in JavaScript (Node.js 6.4.0) let rt_arr=new Array(A.length+1); rt_arr.fill(1); for(i in A) { rt_arr[A[i]-1]=0; } //console.log(rt_arr.findIndex(isZero)+1); return rt_arr.findIndex(isZero)+..

알고리즘 2017.09.26